Why in some frameworks the logic layer is called “Model” whereas in some it is called “Service”. Are they different from each other or just different by naming conventions?
UPDATE 1
The reason I’m asking is because in Zend Framework, a classical MVC framework, everybody uses the concept of Model. Now I’m learning AngularJS and it seems that the word Model disappeared and was replaced by the word service.
What I noticed is that a service is more like a singleton that can be reused again and again (example: a REST client) whereas a model is more related to the data manipulations coming from the controller in the MVC pattern.
2
Model: Fields that belong to the object, methods that help to get/set data from the object (a fullname accessor that returns first + last name)
Service: Methods to perform operations with one or more models, see ‘unit of work’, transactions, etc…
Employee::create should just take a set of data, perform model validation if necessary, and return an Employee Object.
EmployeeService::hireEmployee might create the employee, send them a welcome email, create a mailbox, make them a sandwich, etc… it may return the set of data, or a result code, etc…
This can also affect validation:
Model Validation: Employee must have a id, first and last name, and birthday
Service Validation: Employees for the bartender position must be 21 or over, and approved by a manager.
1
According to my experience, the Model layer within the MVC design pattern refers to every software component involved with data manipulation (POJOs, DAO, all the way to SQL, JDBC, and so on).
Whereas the service layer is actually an addition to MVC:
We know that the Model layer components are invoked inside the Controller layer. Once the latter is built, you come to realize that it doesn’t look concise (messy with dirty code); the Controller may not afford extra details (e.g. formatting request parameters before calling a DAO method that are going to consume them …). Therefore, you might include this extra layer, namely the Service layer.
Eventually, you may encompass your dirty code inside static methods with a meaningful name, parameters and so forth, which would outcome a synthetic Controller layer.
Take a look at this link:
https://stackoverflow.com/questions/2762978/the-purpose-of-a-service-layer-and-asp-net-mvc-2
1
Structurally these base classes are the same, however they are used to classify a different concerns of the Service and Model tiers of the MVCS implementation
Service:- A concrete service class defines the API of an external Service.
Model :- Defines the API of the applications data model.
So, whilst the base classes are alike, the concrete classes created by extending these base classes serve two entirely different purposes.