1 / 14

Design Patterns

Design Patterns. Ric Holt U Waterloo, March 2009. What is a Design Pattern. A Design Pattern systematically names, explains, and implements an important recurring design. These define well-engineered design solutions that practitioners can apply when crafting their applications.

Télécharger la présentation

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 Ric Holt U Waterloo, March 2009

  2. What is a Design Pattern • A Design Pattern systematically names, explains, and implements an important recurring design. • These define well-engineered design solutions that practitioners can apply when crafting their applications.

  3. Why Design Patterns? • Good designers do not solve every problem from first principles. They reuse solutions. • Practitioners do not do a good job of recording experience in software design for others to use. Patterns help solve this problem.

  4. Two Example Patterns • MVC (Model View Controller) • Adapter

  5. 1. MVC Pattern(Model View Controller) • There is a model (subject) which can be thought of as the application • There are one or more views of the object (by observers) • There is a controller that mediates between the model and the view(s).

  6. b a c a b c 50 30 20 Example MVC a = 50% b = 30% c = 20% Views a b c Controller Model [Mancoridis picture]

  7. b a c a b c 50 30 20 Example MVC a = 50% b = 30% c = 20% Views a b c Controller See Interact Model [Mancoridis picture]

  8. Multiple View Problem • Need to keep all the views consistent • If user (or one of users) changes a view, all other views should be updated

  9. Information Hiding:Insulating Model from Presentation • The model is the “back end” or “business logic”, or “application” • To minimize complexity, the model should know as little as possible about • How users interact with system • How many users are there • Any other models

  10. Implementing MVC • There are many choices • Where is list of views (observers) kept? • How is notification of change transmitted? • How manage web interface? • Should a view ask for (or should it be told of) details about changes?

  11. What Kind of Pattern is MVC? • Design pattern proper? • Use it for structuring modest configurations • Architectural pattern? • Use it for overall structure of a software system, defining interactions among services, browsers etc.

  12. 2. Adapter Pattern • You have an existing client (application) that uses an oldinterface to an existing support package. • You are given a newinterface to a new support package • You need to produce an adapter so that: • The client can use the new interface instead of the old one (without changing the client)

  13. Illustration of Adapter Pattern Old interface Old package Client Old interface New interface New package Client Adapter

  14. SpecificRequest() Implementing Adapter Pattern Using Object Composition Old Interface New Interface Client Request() SpecificRequest() inherit adaptee Adapter Request()

More Related