Setting messages from classes in Drupal
Prior to 8.5.x, drupal_set_message is the way.
For &gt;=8.5.0-alpha1, there's a new messenger service, with a note (and example which I won't bother copying):

The procedural functions drupal_set_message() and drupal_get_messages() have been deprecated and replaced with a dedicated Messenger service.
You should now inject this service as a dependency for your own services and controllers: