Académique Documents
Professionnel Documents
Culture Documents
Submitted by :
Gurtej Singh
MIT2018068
Design Patterns
“Each pattern describes a problem that occurs over and over again in our environment, and then
describes the core of the solution to that problem, in such a way that you can use this solution a
million times over, without ever doing it the same way twice”. — Christopher Alexander
Types of Design Patterns
1. Creational
These design patterns are all about class instantiation or
object creation. For ex : Factory Method, Abstract Factory
2. Structural
These are about organizing different classes and objects to
form larger structures and provide new functionality.
For ex : Facade, Flyweight, Private Class Data and Proxy.
3. Behavioral
These are about identifying common communication
patterns between objects and realize these patterns.
For ex : Chain of responsibility, Command, Interpreter, Iterator,
Mediator, Memento, Null Object, Observer, State, Strategy,
Template method, Visitor
Motivation
● You want to draw a forest of trees!
● How would you implement this?
● Millions of tree objects in the program?
○ Memory constraint
● What is the optimal solution?
● Can we implement it so that we create only 1 tree
object?
Flyweight Pattern
● That’s where flyweight comes in!
● If the objects you create have so much common
properties (like trees, only positions are different).
● The activity diagram may be like this with only one
instance.
●
●
●
●
●
●
●
● Then, we have to store positions somewhere!
○ Client can do this for us.
Definition
1. https://en.wikipedia.org/wiki/Flyweight_pattern
2. GoF Design Patterns Book
3. Definition from: C# design patterns, James cooper
4. http://www.dofactory.com/Patterns/PatternFlyweight.
aspx#_self1
5. http://fc07.deviantart.net/fs32/f/2008/218/8/7/Pine_fo
rest_by_softwalls.jpg
6. Oreilly Head First: Design Patterns Book
7. Fry of Futurama for Questions Picture
8. Demo: http://www.javacamp.org/designPattern/flyweight.html
9. http://javatechniques.com/public/java/docs/basics/stri
ng-equality.html
Thank You !