Design Patterns & Refactoring Comparison of the Behavioral Patterns Oliver Haase HTWG Konstanz Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 1 / 7
Encapsulation of the Variation Many behavioral patterns encapsulate the varying concept, clients are loosely coupled to the encapsulated concept: behavioral pattern encapsulated concept strategy algorithm state state dependend behavior broker protocol between objects iterator access to and traversal of collections Without encapsulation, varying concept would be integrated into client object Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 2 / 7
Objects as Arguments Some behavioral patterns define objects that are always used as arguments, e.g. visitor pattern → Visitor always used as argument to accept -call of a Node . Some patterns define object that is passed around as magic token without the clients’ knowledge of its content ( Command object, Memento object). Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 3 / 7
Encapsulation or Distribution of Communication Observer Pattern: Communication is distributed across subjects (observables) and observers Responsibility to preserve consistency is shared. Communication flows at run-time are hard to understand Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 4 / 7
Encapsulation or Distribution of Communication Broker Pattern: Communication is centralized in broker (mediator) object Broker is responsible to preserve consistency Broker is single point of failure and scalability bottle-neck Communication flows at run-time are easier to understand Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 5 / 7
Decoupling of Sender and Receiver An object that uses another object gets dependent on it. The following patterns follow different approaches to minimize this coupling: Command : Sender uses Command object through a small, predefined interface, .i.e. execute operation. Command object uses the receiver’s specific, possibly complex interface. Observer : Subjects notify observers through a simply notify operation, decoupling subjects from observers. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 6 / 7
Decoupling of Sender and Receiver Broker : Sender uses Broker object to communicate with receiver. This decouples senders from receivers, but couples them to broker. Chain of Responsibility : Client is decoupled from receivers through their internal chaining of the request. Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 7 / 7
Recommend
More recommend