Design Patterns & Refactoring Comparison of the Behavioral - - PowerPoint PPT Presentation

design patterns refactoring
SMART_READER_LITE
LIVE PREVIEW

Design Patterns & Refactoring Comparison of the Behavioral - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Design Patterns & Refactoring

Comparison of the Behavioral Patterns Oliver Haase

HTWG Konstanz

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 1 / 7

slide-2
SLIDE 2

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

  • bject

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 2 / 7

slide-3
SLIDE 3

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

slide-4
SLIDE 4

Encapsulation or Distribution of Communication

Observer Pattern: Communication is distributed across subjects (observables) and

  • bservers

Responsibility to preserve consistency is shared. Communication flows at run-time are hard to understand

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 4 / 7

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

  • peration, decoupling subjects from observers.

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 6 / 7

slide-7
SLIDE 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