Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a Controller and a Facade?

In my applications, I used to call Facade methods in the main application using they as Controllers because I thought they are the same thing, but now I think I was wrong.

My application use multiple Facades, each one for a kind of task. If I change to use the Controller, the right way is having only one Controller?

My question here is what is the difference between a Facade and a Controller.

like image 529
Renato Dinhani Avatar asked Apr 27 '12 02:04

Renato Dinhani


People also ask

What is a facade and what is it used for?

Façade, by definition, is the face of a building. It is what you can see from the exterior that protects the interior. Façades are an integral part of the building shell – keeping us humans warm in the winter and cool in the summer, while also providing a barrier from outside elements and even fire in some cases.

What does facade mean in software?

A facade is a class that provides a simple interface to a complex subsystem which contains lots of moving parts. A facade might provide limited functionality in comparison to working with the subsystem directly.

Could you explain the difference between façade vs mediator?

Mediator abstracts/centralizes arbitrary communications between colleague objects. It routinely "adds value", and it is known/referenced by the colleague objects. In contrast, Facade defines a simpler interface to a subsystem, it doesn't add new functionality, and it is not known by the subsystem classes.

Is service layer a facade?

Implementation Variations In the domain facade approach a Service Layer is implemented as a set of thin facades over a Domain Model (116). The classes implementing the facades don't implement any business logic. Rather, the Domain Model (116) implements all of the business logic.


1 Answers

Normally it would be the other way around, as you tend to have fewer facades in your system then controllers. Facades are meant to be wrappers around complex functionality, their primary goal is hiding complexity of an underlying system. You can think of the Facade as a layer wrapping the complex functionality and providing simpler methods to interact with.

A controller, on the other hand, is normally tied to a very specific piece of functionality in the system. It's main goal is to mediate the interaction between a view and a model, or in some cases just a model.

It's more typical to have a facade interacting with several controllers, than vice versa.

like image 140
Perception Avatar answered Sep 23 '22 02:09

Perception