Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant

Similar presentations


Presentation on theme: "An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant"— Presentation transcript:

1 An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant http://www.jpboodhoo.com/blog bitwisejp@gmail.com

2

3 The Problem How do I ensure that a class has only one instance of itself active for the application lifetime, as well as providing access to it?

4 The Singleton Pattern Ensures a class has only one instance, and provide a global point of access to it.

5 Hello Singleton

6 Singleton Tradeoffs Benefits Controlled access to a sole instance Bye bye global variables Liabilities Multihreading Issues Tighter coupling when not done correctly Difficult to test when not implemented correctly

7 The Problem Problem: Sort a list of People How many different ways can you sort a list of people?

8 Naive Sorting

9 What’s Wrong Hint – Think Open Closed Principle

10 The Strategy Pattern Define a family of algorithms, encapsulate each one, and make them interchangeable.

11 Sorting With The Strategy Pattern

12 Strategy Tradeoffs Benefits Remove the need to subclass Eliminate conditional processing. Liabilities Users of List must be aware of different strategies Potential class explosion.

13 The Problem An object in a program has an internal "state," and the behavior of the object needs to change when its state changes.

14 Messy State Implementation

15 The State Pattern Allows an object to alter its behaviour when its internal state changes. The object will appear to change its class.

16 Applying The State Pattern

17 State Tradeoffs Benefits New states can be added easily Goodbye messy conditionals Liabilities Potential class explosion Coupling between state classes (may not be a bad thing)

18 The Problem How do I convert the interface of one class into another interface that the client can work with?

19 The Adapter Pattern Converts the interface of a class into another interface the client expects.

20 The Adapter Pattern * Diagram shamelessly lifted from Head First Design Patterns

21 Applying The Adapter Pattern

22 Many Ways to Implement You can implement a design pattern 100 times and have it come out different each time. Start simple, don’t make your designs unnecessarily complicated.

23 Design Patterns Design Patterns Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Addison-Wesley, 1995 Patterns of Enterprise Application Architecture Patterns of Enterprise Application Architecture Martin Fowler Addison-Wesley, 2003 Enterprise Integration Patterns Enterprise Integration Patterns Gregor Hohpe, Bobby Woolf Addison-Wesley, 2004 Pattern Catalogs Head First Design Patterns Eric Freeman & Elisabeth Freeman O’Reilly, 2004

24 Resources Design Pattern – Gamma,Helm,Johnson,Vlissides Head First Design Patterns – Eric Freeman and Elisabeth Freeman Refactoring to Patterns – Joshua Kerievsky www.jpboodhoo.comwww.jpboodhoo.com – JP Boodhoo’s Web Site (had to throw that one in!!) www.jpboodhoo.com


Download ppt "An Introduction To Design Patterns Jean-Paul S. Boodhoo Independent Consultant"

Similar presentations


Ads by Google