design-patterns.pdf - Design patterns Dr C Constantinides...

This preview shows page 1 - 8 out of 28 pages.

Design patterns Dr. C. Constantinides, P.Eng . Computer Science and Software Engineering Concordia University
2 Design patterns Documentations of specific recurring problems and their solutions. Design patterns originate from the discipline of Architecture. “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.” Christopher Alexander, “A Pattern Language”, 1977.
3 Advantages and characteristics of design patterns Advantages: Help designers reuse successful designs by basing new designs or prior experience. Improve the documentation and maintenance of existing systems. Characteristics: Re-occurrence Reusability Introduced in Computer Science by E. Gamma, R. Helm, R. Johnson, and J. Vlissides, “Design patterns; Elements of reusable object- oriented software”, 1994. (“the gang of four”, or “GoF” book). The GoF book presents a catalog of design patterns; More are being proposed by others.
Design patterns We will cover the following: Strategy [behavioral] Singleton [creational] Observer (pull model) [behavioral] 4
Strategy Problem : 1. How to support varying but related policies offered by a class? 2. How to design for the ability to change these policies at run-time?
5
Sale +getTotal(): Money +setNewStrategy(ISalePricingStrategy):void <<interface>> ISalePricingStrategy +getTotal(Money): Money NormalPricingStrategy +getTotal(Money): Money PointsAwardPricingStrategy +getTotal(Money): Money public Money getTotal(Money money) { return money; } public Money getTotal(Money money) { this . awardPoints = ( int )money.getAmount(); return money; } -strategy: ISalePricingStrategy 6
Strategy /cont. We define classes which represent various strategies: NormalPricingStrategy, PointsAwardPricingStrategy , … We define a context class, Sale, whose behavior varies

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture