problems • Separate the construction of a complex object from its representation • Simplify class creation for classes with complex object(s) • Same Builder can create different class representations with the same process • Always creating a valid object, NOT the right object • Methods names are not predefined, but should be easy to understand
Encapsulates code for construction and representation • Provides control over steps of construction process • Easier reusability of object instantiation • Requires creating a separate ConcreteBuilder for each different type of object • Requires the builder classes to be mutable • Data members of class aren't guaranteed to be initialized • Dependency injection may be less supported Advantages Disadvantages
to its receivers • It should be possible that more than one receiver can handle a request • Define a chain of receiver objects having the responsibility, depending on run-time conditions, to either handle a request or forward it to the next receiver on the chain (if any)
of checking permissions abstract class Voter implements VoterInterface { abstract protected function supports($attribute, $subject); abstract protected function voteOnAttribute($attribute, $subject, TokenInterface $token); } class PostController extends AbstractController { public function show($id) { // check for "view" access: calls all voters $this->denyAccessUnlessGranted('view', $post); }
{ protected function supports($attribute, $subject) { // only vote on Post objects inside this voter // if the attribute is one we support } protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { // … some logic will be here }
(adaptee) into another interface (target) the client require • Work through an adapter to work with (reuse) classes that do not have the required interface • makes two incompatible objects work together without changing their interfaces
each other. Instead of classes communicating directly, and thus requiring knowledge of their implementation, the classes send messages via a mediator object