Search code examples
ooparchitecture

What's the difference between a Controller and a Service?


I'm looking for how to structure the layer of my app between the presentation layer and the model / business object layer. I see examples using Controller classes and others using Service classes. Are these the same things with different names for different methodologies, or is there a more fundamental difference?

Edit: To put the question in context, this is a PHP app using Doctrine as the ORM.


Solution

  • I would say terms like Controller are basically same names for potentially very different things depending on what methodology / framework you are using. At a very high level, they may perform the same action - hence the generic name usage - but their responsibilities and scope within the context of the framework will usually be much more specific and different.

    Eg: The Controller in MVC has little or nothing in common with the Controller layer in WCSF.

    I think these terms like Controller / Service etc are generic and hence have been used in many frameworks but they have a special meaning within the framework of reference.

    Also, specifically, a controller and a service to me are two completely differing concepts.

    Controller is something like a layer that is responsible for orchestrating logic within the application / or an aspect of the application

    Service , to me, is basically the external API through which you expose aspects of your application in a standard manner