im 2042 – information systems modeling and design topic 4 – refining the requirements model....
TRANSCRIPT
IM 2042 ndash Information Systems Modeling and Design
Topic 4 ndash Refining the Requirements Model Design Patterns
Based on chapters 8 and 15 of Bennett McRobb and Farmer
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 2
In This Lecture You Will Learn
About reuse in software development How object-orientation contributes to reuse How to identify and model aggregation composition and
generalisation An approach to modelling components About lsquopatternsrsquo in software development How analysis patterns help to structure a model
what types of patterns have been identified in software development
how to apply design patterns during software development
the benefits and difficulties that may arise when using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 3
Software development has concentrated on inventing new solutions
Recently the emphasis has shifted
Much software is now assembled from components that already exist
Component reuse can save money time and effort
Reuse in Software Development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 4
Reuse in Software Development
Achieving reuse is still hard Reuse is not always appropriate ndash canrsquot assume
an existing component meets a new need Poor model organisation makes it hard to identify
suitable components The NIH (Not-Invented-Here) syndrome Requirements and designs are more difficult to
reuse than code
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 5
Reuse The Contribution of OO
Encapsulation makes components easier to use in systems for which they were not originally designed
Aggregation and composition can be used to encapsulate a group of classes that collectively have the capacity to be reusable subassembly
Generalisation allows the creation of new specialised classes when needed
Components are complex structures that are developed separately from each other and then simply lsquoplugged togetherrsquo to achieve the desired functionality
It has to meet a clear-cut but general need
It has one or more simple well-defined external interfaces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 6
Aggregation and Composition
Special types of association both sometimes called whole-part
A campaign is made up of adverts
Campaign Advert01
Unfilled diamond signifies aggregation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 2
In This Lecture You Will Learn
About reuse in software development How object-orientation contributes to reuse How to identify and model aggregation composition and
generalisation An approach to modelling components About lsquopatternsrsquo in software development How analysis patterns help to structure a model
what types of patterns have been identified in software development
how to apply design patterns during software development
the benefits and difficulties that may arise when using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 3
Software development has concentrated on inventing new solutions
Recently the emphasis has shifted
Much software is now assembled from components that already exist
Component reuse can save money time and effort
Reuse in Software Development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 4
Reuse in Software Development
Achieving reuse is still hard Reuse is not always appropriate ndash canrsquot assume
an existing component meets a new need Poor model organisation makes it hard to identify
suitable components The NIH (Not-Invented-Here) syndrome Requirements and designs are more difficult to
reuse than code
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 5
Reuse The Contribution of OO
Encapsulation makes components easier to use in systems for which they were not originally designed
Aggregation and composition can be used to encapsulate a group of classes that collectively have the capacity to be reusable subassembly
Generalisation allows the creation of new specialised classes when needed
Components are complex structures that are developed separately from each other and then simply lsquoplugged togetherrsquo to achieve the desired functionality
It has to meet a clear-cut but general need
It has one or more simple well-defined external interfaces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 6
Aggregation and Composition
Special types of association both sometimes called whole-part
A campaign is made up of adverts
Campaign Advert01
Unfilled diamond signifies aggregation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 3
Software development has concentrated on inventing new solutions
Recently the emphasis has shifted
Much software is now assembled from components that already exist
Component reuse can save money time and effort
Reuse in Software Development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 4
Reuse in Software Development
Achieving reuse is still hard Reuse is not always appropriate ndash canrsquot assume
an existing component meets a new need Poor model organisation makes it hard to identify
suitable components The NIH (Not-Invented-Here) syndrome Requirements and designs are more difficult to
reuse than code
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 5
Reuse The Contribution of OO
Encapsulation makes components easier to use in systems for which they were not originally designed
Aggregation and composition can be used to encapsulate a group of classes that collectively have the capacity to be reusable subassembly
Generalisation allows the creation of new specialised classes when needed
Components are complex structures that are developed separately from each other and then simply lsquoplugged togetherrsquo to achieve the desired functionality
It has to meet a clear-cut but general need
It has one or more simple well-defined external interfaces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 6
Aggregation and Composition
Special types of association both sometimes called whole-part
A campaign is made up of adverts
Campaign Advert01
Unfilled diamond signifies aggregation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 4
Reuse in Software Development
Achieving reuse is still hard Reuse is not always appropriate ndash canrsquot assume
an existing component meets a new need Poor model organisation makes it hard to identify
suitable components The NIH (Not-Invented-Here) syndrome Requirements and designs are more difficult to
reuse than code
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 5
Reuse The Contribution of OO
Encapsulation makes components easier to use in systems for which they were not originally designed
Aggregation and composition can be used to encapsulate a group of classes that collectively have the capacity to be reusable subassembly
Generalisation allows the creation of new specialised classes when needed
Components are complex structures that are developed separately from each other and then simply lsquoplugged togetherrsquo to achieve the desired functionality
It has to meet a clear-cut but general need
It has one or more simple well-defined external interfaces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 6
Aggregation and Composition
Special types of association both sometimes called whole-part
A campaign is made up of adverts
Campaign Advert01
Unfilled diamond signifies aggregation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 5
Reuse The Contribution of OO
Encapsulation makes components easier to use in systems for which they were not originally designed
Aggregation and composition can be used to encapsulate a group of classes that collectively have the capacity to be reusable subassembly
Generalisation allows the creation of new specialised classes when needed
Components are complex structures that are developed separately from each other and then simply lsquoplugged togetherrsquo to achieve the desired functionality
It has to meet a clear-cut but general need
It has one or more simple well-defined external interfaces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 6
Aggregation and Composition
Special types of association both sometimes called whole-part
A campaign is made up of adverts
Campaign Advert01
Unfilled diamond signifies aggregation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 6
Aggregation and Composition
Special types of association both sometimes called whole-part
A campaign is made up of adverts
Campaign Advert01
Unfilled diamond signifies aggregation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 7
Aggregation is essentially any whole-part relationship
Semantics can be very imprecise
Composition is lsquostrongerrsquo
Each part may belong to only one whole at a time
When the whole is destroyed so are all its parts
Aggregation and Composition
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 8
Adding Generalisation Structure
Add generalisation structures when Two classes are similar in most details but
differ in some respects May differ
In behaviour (operations or methods) In data (attributes) In associations with other classes
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 9
Standard UML techniques can be used to model components
Component internals can be detailed in a class diagram
Component interaction can be shown in a communication diagram
Modelling Components in UML
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 10
Modelling Components in UML
UML has icons for modelling components in structure diagrams (eg class diagrams)
laquo component raquoPayments
TakePayment
laquo component raquoBookings
Provided interface offers services Required interface uses services
Ball-and-socket connector maps provided interface of one component to required interface of another
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 11
Modelling Components in UML
Structure diagrams can mix component icons with other icons eg interfaces
laquointerfaceraquoAllocate Seats
GetFreeSeats(seatType)
AllocateSeat(seatRef)
DeallocateSeat(seatRef)
Flight Management
laquocomponentraquo laquorealizeraquo
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 12
Software Development Patterns
A pattern ldquodescribes a problem which occurs over and over again in
our environment and then describes the core of a 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 twicerdquo
Alexander et al (1977)
Are problem-centred not solution-centred
Are Discovered not invented - they already exist
Complement existing techniques and do not replace them
Capture and communicate ldquobest practicerdquo and expertise
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 13
Software Development Patterns
A pattern is proven solution to a problem that recurs in a particular context
A pattern has
A context = a set of circumstances or preconditions for the problem to occur
Forces = the issues that must be addressed
A software configuration that resolves the forces
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 14
Software Development Patterns
Patterns are found at many points in the systems development lifecycle Analysis patterns are groups of concepts useful in
modelling requirements Architectural patterns describe the structure of
major components of a software system Design patterns describe the structure and
interaction of smaller software components
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 15
Application of Patterns
Applied to software design since early 90rsquos
Now used in in Project management Organisation structures Requirements analysis System design General modelling approaches Programming ndash (called idioms)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 16
Patterns vs Frameworks
Frameworks are partially completed software systems that may be targeted at a specified type of application Framework is a reusable mini-architecture that provides structure and behaviour to all applications of this type
However patterns
are more abstract and general than frameworks
cannot be directly implemented in a particular software environment
are more primitive than frameworks A framework can employ several patterns but a pattern cannot incorporate a framework
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 17
Catalogues amp Languages
A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other
The patterns in a pattern language are more closely related and work together to solve problems in a specific domain
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 18
Key Principles
Key principles that underlie patterns
abstraction
encapsulation
information hiding
modularization
separation of concerns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 19
Key Principles
coupling and cohesion
sufficiency
completeness and primitiveness
separation of policy and implementation
separation of interface and implementation
single point of reference
divide and conquerBuschmann et al (1996)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 20
Pattern Template
Name - meaningful that reflects the knowledge embodied by the pattern
Problem - description of the problem that the pattern addresses (the intent of the pattern)
Context - represents the circumstances or preconditions under which it can occur
Forces - embodied in a pattern are the constraints or issues that must be addressed by the solution
Solution - description of the static and dynamic relationships among the components of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 21
Other aspects of Templates
An example of the use of a pattern that serves as a guide to its application
The context that results from the use of the pattern
The rationale that justifies the chosen solution
Related patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 22
Analysis Patterns
First introduced by Fowler in 1997
1048708 ldquoAnalysis patterns are groups of concepts that represent a common construction in business modellingldquo
1048708 An analysis pattern may be relevant to only one domain or it may span many domains
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 23
Simple Analysis Pattern
Transaction
transactionNumbertransactionDatetransactionTotal
updateTransactionTotal ( )
TransactionLineItem
TransactionLineNumbertransactionLineQuantitytransactionLineValue
comprises
1
An analysis pattern is a structure of classes and associations that is found to occur over and over again in many modelling situations
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 24
Accountability Analysis Pattern
AccountabilityType
Accountability
Time Period
Party
Person
Organization
commissioner
responsible
1
1
1
1
Problem Representing organization structures employmentmanagement professional registration and contracts with asimilar structureSolution Create accountability as a directed relationshipbetween two parties Give it an accountability type to represent the kind of relationship
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 25
GOF Design Patterns
Catalogue of 23 design patterns presented by Gamma et al (1995) patterns known as Gang of Four ndash hence GOF Patterns
Classified as creational structural or behavioural
Typically address issues concerning changeability involves several different aspects maintainability extensibility restructuring and portability
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 26
Creational Patterns
Concerned with the construction of object instances
Separate the operation of an application from how its objects are created
Gives the designer considerable flexibility in configuring all aspects of object creation
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 27
Creational Patterns Singleton
How does one ensure that only one instance of the company class is created
Company
companyName
companyAddress
companyRegistrationNumber
getCompanyDetails()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 28
Creational Patterns Singleton
Solution ndash restrict access to the constructor
Company
- companyInstance - companyName
- companyAddress
- companyRegistrationNumber
+ getCompanyInstance()
+ getCompanyDetails()
Class-scope (or static) attribute
(or static) operation
- Company() Private constructor
The use of class-scope operations allows global access
Class-scope
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 29
Creational Patterns Singleton
Company
- companyInstance
- companyName
- companyAddress
+ getCompanyInstance()
+ getCompanyDetails()
- Company()
+ getCompanyDetails()String- UkCompany()UkCompany
- companyRegistrationNumber
UKCompany
+ getCompanyDetails()String- USACompany()USACompany
- companyRegistrationNumber
USACompany
+ getCompanyDetails()String- FrenchCompany()FrenchCompany
- companyRegistrationNumber
FrenchCompany
The attribute companyRegistrationNumber
has been moved to the subclasses where it is defined
differently in each
The operation getCompanyDetails()
has been moved to the subclasses where it is
polymorphically redefined in each
bullDifferent subclasses of Company can be instantiated as needed depending on run-time circumstances
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 30
Creational Patterns Singleton
+ getInstance()
Singleton
- uniqueInstance
- singletonData
+ getSingletonData()
+ singletonOperation()
- Singleton()
Holds object identifier for the Singleton instance
Returns object identifier for the unique instance
Private constructor mdash only accessible via getInstance()
General form of Singleton pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 31
Structural Patterns
Concerned with the way in which classes and objects are organized
Offer effective ways of using object-oriented constructs such as inheritance aggregation and composition to satisfy particular requirements
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 32
Structural Patterns Composite
MediaClip
play()
VideoClip
play()
SoundClip
play()
bull How can we present the same interface for a media clip whether it is composite or not
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 33
Structural Patterns Composite
Delegates to the play()
operation in the
components
play() is
polymorphically
redefined
VideoClip
play()
SoundClip
play()
AdSequence
play()
addClip()
removeClip()
getChild()
1
How can we incorporate composite structures
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 34
Composite applied to Agate
Collection of MediaClip
object identifiers
for all m in mediaClipCollection mplay()
Delegates to the play() operation in
the components
play() is polymorphically
redefined
AdSequence
mediaClipCollection
play()addClip()removeClip()getChild()changeSequence()
1
MediaClip
play()addClip()removeClip()getChild()
VideoClip
play()
SoundClip
play()
Advert ordered
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 35
Composite Pattern General Form
Collection of Component
object identifiers
for all c in componentCollection
canOperation()
anOperation() is polymorphically
redefined
Composite
componentCollection
anOperation()addComponent()removeComponent()getChild()
1
Component
anOperation()addComponent()removeComponent()getChild()
Leaf
anOperation()
OtherLeaf
anOperation()
Client
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 36
Behavioural Patterns
Address the problems that arise when assigning responsibilities to classes and when designing algorithms
Suggest particular static relationships between objects and classes and also describe how the objects communicate
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 37
Behavioural Patterns State
Consider the class Campaign
It has four states ndash Commissioned Active Completed and Paid
A Campaign object has different behaviour depending upon which state it occupies
Operations have case statements giving this alternative behaviour
The class factored into separate components ndash one for each of its states
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 38
Campaign class could have state pattern applied
If commissioned then
If active then
If completed then
If paid then
Illustrative Structured English for the calcCosts() operation
laquoentityraquo
Campaign
- title- campaignStartDate- campaignFinishDate- estimatedCost- completionDate- datePaid- actualCost- campaignOverheads- advertCollection- teamMembers
+ Campaign() + assignManager()+ assignStaff()+ checkCampaignBudget()+ calcCosts()+ checkStaff()+ getDuration()+ getTeamMembers()+ linkToNote()+ addAdvert()+ listAdverts()+ recordPayment()+ getCampaignDetails()- getOverheads()+ completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 39
Behavioural Patterns State
State pattern applied to the class Campaign
Contains the object identifier of the current state object
CampaignState
addAdvert()calcCosts()completeCampaign()
Commissioned
addAdvert()calcCosts()completeCampaign()
Campaign
currentStateIdentifier
addAdvert()changeState()calcCosts()changeState()completeCampaign()
Active
addAdvert()calcCosts()completeCampaign()
Completed
addAdvert()calcCosts()completeCampaign()
Paid
addAdvert()calcCosts()completeCampaign()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 40
Behavioural Patterns State
Some State pattern objects for Agate ndash note that there are 6 Campaign objects sharing the four State objects
aCampaign
cCampaign
eCampaign bCampaign
fCampaign
dCampaign
Commissioned
Active
Completed
Paid
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 41
General form of State Pattern
State
operation()
ConcreteStateA
operation()
ConcreteStateB
operation()
Context
operation()
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 42
Before Using Patterns
Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem Does the pattern trigger an alternative solution that
may be more acceptable Is there a simpler solution Patterns should not be
used just for the sake of it Is the context of the pattern consistent with that of the
problem Are the consequences of using the pattern acceptable Are constraints imposed by the software environment
that would conflict with the use of the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 43
Using Patterns
After selecting a suitable pattern1 Read the pattern to get a complete overview2 Study the Structure Participants and Collaborations
of the pattern in detail3 Examine the Sample Code to see an example of the
pattern in use4 Choose names for the patternrsquos participants (ie
classes) that are meaningful to the application5 Define the classes6 Choose application specific names for the operations7 Implement operations that perform the
responsibilities and collaborations in the pattern
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 44
Summary
In this lecture you have learned about
How to identify and model aggregation composition and generalisation
Reusable components and how to model them in structure diagrams
What is meant by lsquopatternrsquo and how patterns are used in software development
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 45
Summary
In this lecture you have learned about what types of patterns have been identified in
software development how to apply design patterns during software
development the benefits and difficulties that may arise when
using patterns
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)
copy Bennett McRobb and Farmer 2005 IM 2042 ndash Information Systems Modeling amp Design Topic 4 Slide 46
References
Bennett McRobb and Farmer (2005)
Ambler (2003)
Cheesman and Daniels (2001)
Coad (1997)
Fowler (1997)
(For full bibliographic details see Bennett McRobb and Farmer)