Reputation:
I am in a middle of task to revamp a PHP System, however there are too many classes communications, so I searched for a pattern to solve such problem, and I found that Mediator pattern aims to solve a complex objects communications also Facade may help by reducing redundant code and calls, so which one should I consider?
Thank you,
Upvotes: 0
Views: 680
Reputation: 2975
From your description I understand that what concerns you (most) is the communication between the components. In this case, you are right you should go with the Mediator pattern.
The Mediator pattern is a behavioral one and will allow a looser coupling of the interacting components while encapsulating the interaction and communication logic. In other words, your interacting components (classes) will have less burden in regards of their inter-communication and a mediator object will orchestrate how they interact. It also gives you a single point where the communication/interaction logic is placed. Great for complex but well defined communication "rules".
The Facade pattern is a structural one and is used to wrap an existing functionality in order to provide a simpler interface for accessing this functionality. It could be also useful if you would wrap a group of your classes behind the facade and others could use the simplified interface.
But if you find yourself in need to create many facades for different groupings and combination of calls between them, Mediator is the best choice.
Upvotes: 2