5. What is so special about
At any given moment, somewhere in the world,
someone struggles with the same software design
problems you have. But better yet, someone has
already solved your software design problems.
Tried-and-true, road-tested, successfully used by
developers to create functional, elegant, reusable, and
6. Use inheritance
The Duck Game
Someone wants ﬂy()
Let’s Design it together Code reuse?
Waiting for a design
pattern to save the
day? No :P
Design Priciple 1
Identify the aspects of
your application that
vary and separate them
from what stays the
7. The one constant in
8. The one constant in
9. Adding a spice of ﬂexibility
Design Priciple 2
Program to an interface,
not an implementation
10. OO Design Principles
Indentify the aspects of your application that vary and
separate them from what stays the same.
Program to an interface, not an implementation.
Favor composition over inheritance
11. Strategy pattern
Deﬁnes a family of algorithms, encapsulates each one,
and make them interchangeable.
Strategy lets the algorithm vary independently from
clients that use it.
How do I use design patterns?
If design patterns are so great, why can’t somebody
build a library of them so I don’t have to?
Aren’t libraries and frameworks also design patterns?
Knowing OO basics is enough? What makes me a
good OO designer?
13. The Observer Pattern
14. Observer Pattern
The most heavily used pattern in the JDK
Publisher + subscriber = Observer Pattern
Deﬁnes a one-to-many relationship.
Deﬁnition: deﬁnes one-to-many dependency between
objects so that when one object changes state, all of
its dependencies are notiﬁed and updated
16. DP Categories
Concern the ways and means of object instantiation
Deal with the mutual composition of classes or
Analyze the ways in which classes or objects interact
and distribute responsibilities among them.
23. Singleton Pattern
One of a kind objects.
Private constructors? Useful?
Ensures a class has only one instance, and provide a
global point of access to it.
24. Command Pattern
Encapsulates a request as an object, thereby letting
you parameterize other objects with different requests,
queue or log requests, and support undoable
25. Adapter and Facade
Adapter pattern: converts the interface of a class into
another interface the clients expect. Adapters lets
classes work together that couldn’t otherwise because
of incompatible interfaces.
Facade pattern: provides a uniﬁed interface to a set of
interfaces in a subsystem. Facade deﬁnes a higher-
level interface that makes the subsystem easier to use.
26. OO Design Principle
Least Knowledge: talk only to your immediate friends.
How java violates it?
How facade use it?
27. Session 4
28. Iterator Pattern
Provides a way to access the elements of an aggregate
object (collection) sequentially without exposing its
29. OO Design Principle
Single Responsibility: A class should have only one
reason to change.
Cohesion: a term measures how closely a class or a
module supports a single purpose or responsibility.
High Cohesion -> if a class is designed around a set of
30. Composite Pattern
Allows you to compose objects into tree structures to
represent part-whole hierarchies, Composite lets clients
treat individual objects and compositions of objects
31. Session 5
32. State pattern
A little known fact: the strategy and state patterns were
twins separated at birth.
Allows an object to alter its behavior when its internal
state changes. The object will appear to change its
33. Proxy Pattern
Deﬁnition: Provides a surrogate or placeholder for
another object to control access to it.
34. Compound Patterns
Patterns are often used together and combined within
the same design solution.
A compound pattern combines two or more patterns
into a solution that solves a recurring or general