1 / 15

Design Patterns

Design Patterns. Pepper. Find Patterns. Gang of Four created 23 Siemens published another good set http://www.blackwasp.co.uk/GofPatterns.aspx http://www.javacamp.org/designPattern/ Just Singleton pattern: http://www.oodesign.com/singleton-pattern.html

Download Presentation

Design Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design Patterns Pepper

  2. Find Patterns Gang of Four created 23 Siemens published another good set • http://www.blackwasp.co.uk/GofPatterns.aspx • http://www.javacamp.org/designPattern/ Just Singleton pattern: • http://www.oodesign.com/singleton-pattern.html • http://www.blackwasp.co.uk/Singleton.aspx

  3. Singleton • When there should only be one shared instance in a system - global variable • Ensure that only one instance of a class is created. • Provide a global point of access to the object.

  4. Code Guide • Create the class • Use the class Singleton.getInstance().doSomething();

  5. More Efficient If we see that the singleton object is already created we just have to return it without using any synchronized block.

  6. How can your project use this? • Log file class • Audit file class

  7. Design patterns • A design pattern is a way of reusing abstract knowledge about a problem and its solution. • A pattern is a description of the problem and the essence of its solution. • It should be sufficiently abstract to be reused in different settings. • Pattern descriptions usually make use of object-oriented characteristics such as inheritance and polymorphism. Chapter 7 Design and implementation

  8. Pattern elements • Name • A meaningful pattern identifier. • Problem description. • Solution description. • Not a concrete design but a template for a design solution that can be instantiated in different ways. • Consequences • The results and trade-offs of applying the pattern. Chapter 7 Design and implementation

  9. The Observer pattern • Name • Observer. • Description • Separates the display of object state from the object itself. • Problem description • Used when multiple displays of state are needed. • Solution description • See slide with UML description. • Consequences • Optimisations to enhance display performance are impractical. Chapter 7 Design and implementation

  10. The Observer pattern (1) Chapter 7 Design and implementation

  11. The Observer pattern (2) Chapter 7 Design and implementation

  12. Multiple displays using the Observer pattern Chapter 7 Design and implementation

  13. A UML model of the Observer pattern Chapter 7 Design and implementation

  14. Good Examples of Use • Very Simple use example: http://javarevisited.blogspot.com/2011/12/observer-design-pattern-java-example.html • MVC example: http://www.javaworld.com/article/2077258/learn-java/observer-and-observable.html • Example using listener: http://www.vogella.com/tutorials/DesignPatternObserver/article.html • Good description: • http://www.blackwasp.co.uk/Observer.aspx

  15. Design problems • To use patterns in your design, you need to recognize that any design problem you are facing may have an associated pattern that can be applied. • Tell several objects that the state of some other object has changed (Observer pattern). • Tidy up the interfaces to a number of related objects that have often been developed incrementally (Façade pattern). • Provide a standard way of accessing the elements in a collection, irrespective of how that collection is implemented (Iterator pattern). • Allow for the possibility of extending the functionality of an existing class at run-time (Decorator pattern). Chapter 7 Design and implementation

More Related