Pattern Oriented Design: Design Patterns Explained


Download Pattern Oriented Design: Design Patterns Explained


Preview text

CSC 335: Object-Oriented Programming and Design
Pattern-Oriented Design
by Rick Mercer based on the GoF book and
Design Patterns Explained A New Perspective on Object-Oriented Design Alan Shalloway, James R. Trott Addison Wesley ISBN 0-201-71594-5
1

Using Patterns to Design
 There are 23 Object-Oriented design patterns cataloged in the GoF book--we’ve considered 10 so far (Fall 09)
Iterator, Observer, Strategy, Composite, Singleton, Flyweight, Command, Template, Chain of Responsibility, Decorator
 We'll use some patterns to help design a system
The new case study is in electronic retailing over the internet (An Ecommerce system) Several design decisions will be aided by knowledge of existing design patterns
at a fairly high level of abstraction
2

Plan too much, plan ahead, or don’t plan at all?
 Development of software systems can suffer from analysis paralysis: attempt to consider all possible changes in the future
 At other times developers jump to code too quickly
there is tremendous pressure to deliver, not maintain
 Life’s three certainties for software developers
Death, Taxes, and Changes in Requirements
 There is a middle ground for planning for change
3

How will change occur
 First, anticipate that changes will occur  Consider where they will change, rather than the
exact nature of the changes  These issues will come up in the Ecommerce case
study
4

What is variable in the design?
Consider what is variable in your design
Instead of focusing on what might force a change to your design
Consider what you might want to change Encapsulate the concept that varies
– this is a theme of many design patterns
 Hopefully there are long term benefits without a lot of extra work up front
5

OO Design Patterns Used
In the upcoming case study, these design patterns will help make for a system that is good design
Strategy Singleton Decorator Observer
We've considered all four
6

An Ecommerce System
There is a TaskController object that handles sales requests over the internet
When the sales order is requested, the controller delegates to a SalesOrder object
7

Assign Responsibilities

SalesOrder responsibilities:
Allow users to make an order using GUI input Process the order Print a sales receipt

TaskController

SalesOrder +calcTax():double

SalesTicketPrinter

8

Changing Requirements
Start charging taxes on order from customers
need to add rules for taxation, but how?
modify existing SalesOrder to handle U.S. taxes extend the existing SalesOrder object and modify the tax rules so it applies to the new country
This is an inheritance solution
9

Subclassing Solution

TaskController
US Tax Rules Canadian Tax Rules

SalesOrder
+calcTax():double

SalesTicketPrinter

CanadianSalesOrder
+calcTax():double
10

Preparing to load PDF file. please wait...

0 of 0
100%
Pattern Oriented Design: Design Patterns Explained