Design Patterns - 3
Design Patterns - 3
25
1
Software Re-Engineering
Course Code: SE473
02/08/
25
2
Contents
• Introduction to OO concepts
• Introduction to Design Patterns
• What are Design Patterns?
• Why use Design Patterns?
• Elements of a Design Pattern
• Design Patterns Classification
• Pros/Cons of Design Patterns
• Popular Design Patterns
• Conclusion
3
• References
Observer Definition
4
Design Principles
• Identify 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
• Strive for loosely coupled designs between objects that interact
9
Design Principles
• Identify 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
• Strive for loosely coupled designs between objects that interact
• Classes should be open for extension, but closed for modification
10
• Cons
• Results in problems if there is code that relies on the concrete
component’s type
11
Proxy Definition
12
Proxy
• Pros
• Prevents memory wastage
• Creates expensive objects on demand
• Cons
• Adds complexity when trying to ensure freshness
13
Facade Definition
14
Design Principles
• Identify 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
• Strive for loosely coupled designs between objects that interact
• Classes should be open for extension, but closed for modification
• Principle of least knowledge – talk only to your immediate friends
15
• Cons
• Results in more rework for improperly designed Façade class
• Increases complexity and decreases runtime performance for large
number of Façade classes
16
Adapter Definition
17
Adapter
• Pros
• Increases code reuse
• Encapsulates the interface change
• Handles legacy code
• Cons
• Increases complexity for large number of changes
18
23
Good Design
Maintainability
Extensibility
Scalability
Testability
Reusablilty
Design Patterns
Singleton
Abstract Factory
DAO
Strategy
Decorator
Design Principles
Program to an interface, not an implementation
High cohesion
Low coupling
Open-Closed
Separation of concerns 24
References
• Design Patterns: Elements of Reusable Object-Oriented Software. Gamma, Helm, Johnson,
and Vlissides (GoF). Addison-Wesley, 1995.
• Head First Design Patterns. Freeman and Freeman. O’REILLY, 2004.
• Design Patterns Explained. Shalloway and Trott. Addison-Wesley, 2002.
• Patterns of Enterprise Application Architecture. Fowler. Addison-Wesley, 2003.
• Core J2EE Pattern Catalog, Sun Developer Network,
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
• Object Oriented Software Construction. Meyer, Prentice Hall, 1988.
25
Thank You!