Welcome Guest, Not a member yet? Register   Sign In
Poll: Add the possibility of using a Service Layer?
You do not have permission to vote in this poll.
9 52.94%
4 23.53%
4 23.53%
Total 17 vote(s) 100%
* You voted for this item. [Show Results]

Add the possibility of using a Service Layer

Hi all,

In thread http://forum.codeigniter.com/thread-1651.html I proposed to use a service layer. Experienced developers know the advantage of a service layer and so it would be nice if it could be used in CodeIgniter. To be very clear: I do not suggest you HAVE TO use it, but you CAN use it if you want.

Anybody who does not know what a service layer is, please read some articles on the internet about "service layers". Sometimes they are also called "Application Layer" (or wrongly "Business Logic Layer") .

After reading, things you must understand:

- A service layer is a thin layer between your controller and your model(s).

- A service layer has nothing to do with a web service.

- "A service layer can be used as an interface for different clients." This is Enterprise Architecture Software stuff. That is not what we are talking about.

- A service layer does not contain the business logic. The business logic stays in the models (where it belongs).
See http://www.martinfowler.com/bliki/Anemic...Model.html (read the part at the end about "Application Layer")

- If you do not need it, do not use it!
See http://codeutopia.net/blog/2011/05/22/yo...s-are-okay (read the WHOLE article and the comments)
or http://programmers.stackexchange.com/que...519#162519 (read the answers)

What are the advantages?

- separation of concerns;
- encapsulation of the application's business logic;
- the controller is kept thin;
- better testable (dependencies are abstracted away and you can mock the methods in the layer)

What are the disadvantages?

- possible over engineering (but again: when you do not need it, do not use it)

It is possible to create a service layer in CodeIgniter 3 (as you can see in my example in thread http://forum.codeigniter.com/thread-1651.html), but not the way it should be done. It should be part of the framework.In this way you can create a service (MyService) by extending core class "Service", which should be part of 'system', the same way you extend "Model" and "Controller". The service layer just adds an extra level of abstraction. On itself it doesn't do anything. Adding it to the CodeIgniter framework is easy. It is a small change with little impact.

Note: If you have never used a service layer (application layer), you might think: "He I like CodeIgniter because it is simple and I do not need this.".
You are right, you can do without it, but after using it, you probably understand why it is very useful indeed. So in doubt, please vote 'maybe'.

So what do you think?

Messages In This Thread
Add the possibility of using a Service Layer - by RWCH - 04-12-2015, 02:37 PM

Theme © iAndrew 2016 - Forum software by © MyBB