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.

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

For Error Message,

For Warning Message,

For Notice Message,

ManagerInterface magento 2
Message manager Magento 2