Chapter 7. Models and services: How are they different?
You might have heard of
MVC and wondered why the
S was added for the Robotlegs
Why separate models from services when they both deal with data most of the
Models and services are very similar, but understanding their important differences can help you to use them more effectively. By separating models from services, we provide a clear line in the sand for our classes—boxing off the functionality that they should contain. A service doesn’t store data. A model doesn’t communicate with the outside world to retrieve data. Still—they are closely related. A model is empty without the appropriate service, and a service has no purpose without the models.
Models and Services usually extend Actor
Actor is a
very simple base class—just a dependency on the
eventDispatcher (a property of
Actor) that is shared
throughout the application. This allows your models and services to
dispatch state and status updates that the whole application can pick
It is important to understand that you do not
need to extend
Actor is provided for your convenience, to
give you the core functionality that is commonly needed by models and
services in a Robotlegs application. If your models and services don’t
need that core functionality, or you would like them to be reused in a
non-Robotlegs code base, you can provide the functionality of
Actor manually without
They don’t listen, they only talk
Models and services ...