Pattern Oriented Development: A Practical Approach To Building Software Agenda
Pattern Oriented Development: A Practical Approach To Building Software Agenda
Conceptual
describes what you want, now how you’ll get it
requirements are often specified at a conceptual level
“we need to handle inventory in LIFO, FIFO, average
cost”
Specification
the interfaces of our classes
how objects “talk” to each other
our product class’ methods look like …
Implementation
the code itself Mop Broom Sponge
The Problem
TaskController
As soon as we get new variations in tax we
have to modify our SalesOrder object.
SalesOrder
It also has the problem of possibly creating a
large object if it is responsible for more than one
thing
New Requirement -
Using Inheritance for Specialization
Multiple Tax Domains
Eventually need to handle different tax rules.
We can solve this problem by specializing our
•US Tax
first SalesOrder object to handle the new tax
•Canadian Tax
rules.
TaskController
One Solution
original calcTax that
method calcTax does US tax
SalesOrder
// use switch on type of tax rule to be used + calcTax()
// TYPE US:
// calc tax based on US rules new (overriden) calcTax
// break that does Canadian tax
// TYPE CANADIAN:
// calc tax based on Canadian rules
// break
CanadianSalesOrder
+ calcTax()
We need different behavior at different times; The Strategy pattern is a pattern that tells us
either for different things we are working on or how to identify a set of rules that conceptually
for different clients asking us to do work. do the same thing.
In our example: tax.
GoF Intent: Define a family of algorithms, 1) identify a common way to communicate with
encapsulate each one, and make them all implementations of the rule
interchangeable. Strategy lets the algorithm 2) define an interface or abstract class that
vary independently from clients that use it. * defines this communication
* Design
Patterns, Elements of Reusable Object-Oriented Software, 3) implement each variation of the rule as an
Gamma, Helm, Johnson, Vlissides implementation or derivation
T
a
CalcTax x
+ taxAmount(itemSold : Salable, qty : Double, unit : Double) : double Task US Tax
Controller Sales
I
Order n
USTax CanTax t ... Can Tax
e
r
fa
ce
class SalesOrder {
SalesOrder::process {
public process ()
USTax CanTax ...
...
tax= myTax.calctax( qty, price); tax= myTax.calctax( qty, price);
... ...
} }
}
©Net Objectives, 8/3/2004 39 NetObjectives 40
Who Knows Which Rule to Use What Happens Now
With Changing Requirements
Before, TaskController needed to know either If we get a new tax requirement, we only need
the value of the tax switch to set or which to
SalesOrder to instantiate. derive the new class from the CalcTax class
It can now instantiate the appropriate CalcTax modify the TaskController or the Configuration file.
object. this may, in fact, work with a data dictionary so even it
doesn’t need to change
No other objects change
OR, can have a configuration file that the
SalesOrder class uses to figure out the correct
CalcTax object
US Sales Canadian Sales German Sales US Sales Canadian Sales German Sales
calculate use UPS rates use Canadian shipper use German shipper calculate use UPS rates use Canadian shipper use German shipper
freight freight
verify use US Postal use Canadian Postal use European Postal verify use US Postal use Canadian Postal use European Postal
address rules rules rules address rules rules rules
calculate tax use state and use GST and PST use German VAT calculate tax use state and use GST and PST use German VAT
local taxes local taxes
money US $ Canadian $ Euro $ money US $ Canadian $ Euro $
dates mm/dd/yyyy dd/mm/yyyy dd/mm/yyyy dates mm/dd/yyyy mm/dd/yyyy dd/mm/yyyy
max weight 30 kg max weight 70 lbs none 30 kg
Are there maximum weights in US and Canada? Maybe not. "Sometimes yes, sometimes no…"
Maybe so, and the customer forgot to mention them.
Now we have a good, specific question to ask.
Customers are good at answering specific questions.
©Net Objectives, 8/3/2004 71 NetObjectives ©Net Objectives, 8/3/2004 72 NetObjectives
It Does Get More Complicated Use Mini-Matrix for Complex Cases
have a US customer.
money We can use Money objects that can contain Currency andAmount money
fields that automatically convert as needed..
dates We can use Date objects that can display as required for the country dates
the customer is in.
max weight max weight
The objects in this row can be implemented as a Strategy pattern
encapsulating the “max weight” rule.
We need to create families of objects for The Abstract Factory pattern gives us a way to
particular situations. That is, particular clients implement a set of objects corresponding to a
need particular sets of instantiations. particular case.
In our problem, we can use an Abstract Factory
GoF Intent: Provide an interface [a set of to contain the rules for which objects we need
methods] for creating families of related or for each case we have.
dependent objects without specifying their The possible combinations are now handled by
concrete classes.* the Abstract Factory.
The rest of the software has to deal only with
* Design
Patterns, Elements of Reusable Object-Oriented Software, the objects as components.
Gamma, Helm, Johnson, Vlissides
Client/Application AbstractFactory
y + makeCalcTax()
or + makeCalcFrieght()
t
c + makeAddrRules()
a
F US Case
I
Canada
n ... USAF CanAF
t Case
e
r
fa
ce
makeCalcTax: makeCalcTax:
return new USTax() return new CanTax()
makeCalcFreight: makeCalcFreight:
The interface of the Abstract Factory defines which objects return new USLocal() return new CanLocal()
the factory can create. Each implementation decides on makeAddrRules: makeAddrRules:
return new USAddr() return new CanAddr()
which ones to create. This enables a calling object to get the
objects it will need for a specific case.
©Net Objectives, 8/3/2004 83 NetObjectives ©Net Objectives, 8/3/2004 84 NetObjectives
Using The Abstract Factory The Abstract Factory Designed
y
o r
t
US Sales Canadian Sales German Sales c
a
calculate F US Case
freight Task T
Controller I a
Java
The Abstract Factory Designed Implementation of Factory
Abstract class AbstractFactory { class CanAF implements AbstractFactory {
TaskController
SalesOrder abstract CalcTax makeCalcTax();
CalcTax abstract CalcFreight makeCalcFreight(); public CalcTax makeCalcTax() {
+taxAmount():double abstract AddressRules makeAddrRules(); return new CanTax();
public static AbstractFactory }
getAFtoUse(){ public CalcFreight
USTax CanTax GermanTax // Decide whether to return makeCalcFreight() {
AbstractFactory // USAF instance or CanAF instace return new CanFreight();
} }
+makeCalcTax():CalcTax
+makeAddressRules:AddressRules } public AddressRules
+makeCalcFreight():CalcFreight makeAddrRules() {
class USAF implements AbstractFactory { return new CanAddr();
public CalcTax makeCalcTax() { }
AddressRules
USAF CanAF GermanAF return new USTax(); }
+validate():boolean }
public CalcFreight class SalesOrder {
makeCalcFreight() { private CalcTax myTax;
USAddr CanAddr GermanAddr return new USFreight(); private CalcFreight myFreight;
} private AddressRules myAddr;
public AddressRules makeAddrRules() { public SalesOrder
CalcFreight
return new USAddr(); (AbstractFactory myAF) {
+taxAmount():double
} myTax= myAF.makeCalcTax();
}
}
USFreight CanFreight GermanFreight }
89 90
Agile Development – Aug 5, Berkeley Agile Use Cases (AUC) Agile software development is based on a simple
concept: work on the most important things first, and iteratively look for what is
'now' the most important thing. By doing this a development team is able to adapt
Test-First Techniques Using xUnit and Mock Objects – to changes as they occur, and maximize effectiveness of the development effort.
We use the term "Agile Use Cases" to refer to an incremental technique for
Aug 26, Cupertino iteratively developing Use Cases and refining them into software requirements
using the Ever-Unfolding Story. Agile Use Cases provide for frequent validation of
the requirements, thus supporting agile development.
These courses are similar in content, but with different focus: WEUC is for larger, more
traditional, projects; while AUC is designed to support agile developments. Each of these 3-day
courses consists of lecture and hands-on exercises, and the use case portion is largely based on
Alistair Cockburn's book "Writing Effective Use Cases" - winner of the Jolt Productivity Award for
For more information see 2001.
http://www.netobjectives.com/events/pr_main.htm
Agile Development Best Practices In simple terms, an Agile Project is Refactoring, Unit Testing, and Test-Driven Development
one that is predicated on making sure it is always doing the right thing, The practice of Agile Software Development requires, among
not merely following a plan that has since gone out of date. The other things, a high degree of flexibility in the coding process. As
cornerstone of this approach is getting and adapting to feedback as the we get feedback from clients, stakeholders, and end users, we
project progresses. Most projects can't do this, so they fall further behind want to be able to evolve our design and functionality to meet
and either fail or provide inferior products. Changes are of many types, their needs and expectations. This implies an incremental
but the most common (and important) changes are to the system's process, with frequent (almost constant) change to the code
requirements. This course analyzes what it means to be an agile project, we're working on. Refactoring, the discipline of changing code
and provides a number of best practices that provide and/or enhance without harming it, is an essential technique to enable this
agility. Different agile practices (including RUP, XP and Scrum) are process. Unit testing, which ensures that a given change has not
discussed. caused an unforeseen ripple effect in the system, is another.
Effective Project Management Managing software organizations is Agile Software Development with Design Patterns
difficult, as there are many different project personalities. The Developing software with Agility requires a flexible project
personalities that we find range from formal with high-ceremony (stuffy) management paradigm, with the guiding principles that Design
to informal with individual heroes. Teams seem to be either straight- Patterns can provide. This course analyzes what it means to be an agile
jacketed or thrashing - how can we achieve balance? One answer is project, and provides a number of best practices that enhance agility
agility, which loosens the straight-jackets on the one hand and adds a (focusing on XP). After teaching several patterns and the principles
little formality on the other. This course presents the basics of effective underneath them, the course goes further by showing how
Project Management, practiced in an agile manner. patterns can work together with agile development strategies to
create robust, flexible, maintainable designs.
Design Patterns Explained: A New Perspective on Object-Oriented On-line/Instructor Led Java Language Training This is our on-line
Design This course goes beyond merely teaching several design equivalent of our 5-day Java training. This is not a self-study program
patterns. It also teaches the principles and strategies that make design where you get e-mail answers to your question. This is a high-touch training
patterns good designs. This enables students to use these advanced program where you work in frequent (albeit remote) contact with both the
design techniques in their problems whether design patterns are even instructor and your student community. The core of the Java language is
present. After teaching several patterns and the principles underneath taught as well as some SWING and many of the core Java classes. It
them, the course goes further by showing how patterns can work requires about 4 hours a week from each participant and takes place over 12
together to create robust, flexible, maintainable designs. weeks.
©Net Objectives, 8/3/2004 101 NetObjectives ©Net Objectives, 8/3/2004 102 NetObjectives
©Net Objectives, 8/3/2004 103 NetObjectives ©Net Objectives, 8/3/2004 104 NetObjectives
C++ and XML Bibliography
XML and Its Family of Technologies. XML is a powerful new standard for
data modeling and communication, controlling presentation, and inter/intra-
process communication. As XML is a cross-platform tool, it is a natural fit
for the Java programming language, which is also operating system
independent. This course introduces the student to XML and its primary
supportive technologies such as SAX/DOM, DTD/Schema, JDOM, and XSLT,
with an emphasis on the motivations behind these tools and the way they
interrelate. The instructor will then provide detailed, practical examples of
how these tools can be used in a Java-based project. Best place to buy books: www.bestbookbuys.com
Full bibliography at http://www.netobjectives.com/resources/rs_bks.htm
©Net Objectives, 8/3/2004 105 NetObjectives ©Net Objectives, 8/3/2004 106 NetObjectives
©Net Objectives, 8/3/2004 109 NetObjectives ©Net Objectives, 8/3/2004 110 NetObjectives
©Net Objectives, 8/3/2004 115 NetObjectives ©Net Objectives, 8/3/2004 116 NetObjectives
Notes Notes
©Net Objectives, 8/3/2004 117 NetObjectives ©Net Objectives, 8/3/2004 118 NetObjectives
Notes Notes
©Net Objectives, 8/3/2004 119 NetObjectives ©Net Objectives, 8/3/2004 120 NetObjectives