Display success and error messages using ManagerInterface Magento 2

Magento 2, You can show Success and Error Message Using Interface Magento\Framework\Message\ManagerInterface.

You can display success message Using addSuccessMessage( ) and display error message using addErrorMessage( ) function.

addError( ), addSuccess( ), addWarning( ) and addNotice( ) methods are deprecated.

You can directly fetch Object of Magento\Framework\Message\ManagerInterface in controller file but for other files like Plugin, Observer, Model, Block or Helper you need to instantiate an object in your __construct( ) method.

public function __construct(
    \Magento\Framework\Message\ManagerInterface $messageManager
) {
    $this->messageManager = $messageManager;

Now You can display messages using the below way,
For Success Message,

$message = __('Success Message'); 

For Error Message,

$message = __('Error Message'); 

For Warning Messages,

$message = __('Warning Message'); 

For Notice Message,

$message = __('Notice Message'); 
ManagerInterface magento 2
Message manager Magento 2