Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Design Patterns

By: Ashutosh Pal

Agenda
Why Design Patterns ? Types of Design Patterns Rationale behind different Design Patterns
Abstract Factory Builder Factory Method Prototype Singleton Bridge Adaptor Composite Decorator Faade Flyweight Proxy Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor

Creational Patterns

Structural Patterns

Behavioral Patterns

Types of Design Patterns

Creational Patterns
Describes how classes and objects should be created idea is to make the system independent of how its objects are created and composed. Inheritance is used for varying the class that instantiated While, delegation is used for object instantiation

Structural Patterns
Describes how classes and objects should be composed to form larger structures Making 2 independently developed stuff work together e.g. Adapter Structure for sharing objects e.g. flyweight Building up class hierarchies e.g. Composite Dynamic and recursive composition of objects e.g. Decorator

Behavioral Patterns
Describing algorithms e.g. Strategy, template method Distributing responsibilities among objects e.g. chain of responsibility, mediator Describing the pattern of communication between objects e.g. observer, visitor etc.

Chain of Responsibility

Visitor
Rationale
If you have an Hierarchical data structure and you want to perform operations like saveInXML, saveIn YAML etc. on the complete structure, then following will be the sub-tasks
Traversal The Operation itself

What you should NOT do


Create global functions like saveInXML, saveInYAML etc. that perform both traversal and the operation Add member methods in the data structure that will perform these operations

What you should do


Keep the traversal logic inside the data structure in the accept methods Put the operations logic in a separate visitor class

You might also like