a uml-based pattern specification technique
DESCRIPTION
A UML-Based Pattern Specification Technique. IEEE TRANSACTION ON SOFTWARE ENGINEERING, VOL. 30, NO. 3, MARCH 2004 Robert B. France, Member, IEEE Computer Society, Dae-Kyoo Kim, Student Member, IEEE, Sudipto Ghosh, Member, IEEE Computer Society, and Eunjee Song, Student Member, IEEE. - PowerPoint PPT PresentationTRANSCRIPT
A UML-Based Pattern A UML-Based Pattern Specification TechniqueSpecification Technique
Presented by Chin-Yi TsaiPresented by Chin-Yi Tsai
IEEE TRANSACTION ON SOFTWARE ENGINEERING, VOL. 30, NO. 3, IEEE TRANSACTION ON SOFTWARE ENGINEERING, VOL. 30, NO. 3, MARCH 2004MARCH 2004
Robert B. France, Member, IEEE Computer Society, Dae-Kyoo Kim, Robert B. France, Member, IEEE Computer Society, Dae-Kyoo Kim, Student Member, IEEE,Student Member, IEEE,Sudipto Ghosh, Member, IEEE Computer Society, and Eunjee Song, Sudipto Ghosh, Member, IEEE Computer Society, and Eunjee Song, Student Member, IEEEStudent Member, IEEE
2
OutlineOutline Introduction Introduction
BackgroundBackground
Specifying Pattern SolutionsSpecifying Pattern Solutions
Specifying Visitor Pattern SolutionsSpecifying Visitor Pattern Solutions
An Analysis of Early ExperienceAn Analysis of Early Experience
Related WorkRelated Work
Conclusion and Further WorkConclusion and Further Work
3
IntroductionIntroduction
A design pattern describes a family of solutions A design pattern describes a family of solutions for a class of recurring design problems.for a class of recurring design problems.
Pattern specification languages that are based Pattern specification languages that are based on familiar software modeling concepts are on familiar software modeling concepts are more likely to be usable by software more likely to be usable by software developers.developers.
Pattern specification expressed in the UML:Pattern specification expressed in the UML: Standard for object-oriented modelingStandard for object-oriented modeling MDA that supports the use of models as primary MDA that supports the use of models as primary
artifacts of developmentartifacts of development
4
Introduction (cont’d)Introduction (cont’d)
The pattern specification created by The pattern specification created by thetechnique are metamodels that thetechnique are metamodels that characterize UML design models of pattern characterize UML design models of pattern solution.solution.
A pattern’s metamodel is obtained by A pattern’s metamodel is obtained by specializing the UML metamodel.specializing the UML metamodel.
5
BackgroundBackground
A pattern solution is described form two A pattern solution is described form two perspectives:perspectives: The structural viewThe structural view The interaction viewThe interaction view
6
Specializing the UML MetamodelSpecializing the UML Metamodel UML four-layer architectureUML four-layer architecture
The UML metamodelThe UML metamodel Class diagramClass diagram Well-formedness rulesWell-formedness rules
The UML metamodel can be specialized to produce a The UML metamodel can be specialized to produce a restricted form of the UML metamodel that defines a proper restricted form of the UML metamodel that defines a proper subset of valid UML model.subset of valid UML model.
7
Specializing the UML Metamodel Specializing the UML Metamodel (cont’d)(cont’d)
Specializing the UML metamode to obtain a Specializing the UML metamode to obtain a pattern specification:pattern specification: Specializing the abstract syntax by subtyping Specializing the abstract syntax by subtyping
UML metamodel classes and by making the well-UML metamodel classes and by making the well-formedness rules more restrictiveformedness rules more restrictive
Defining parameterized OCL constraintsDefining parameterized OCL constraints
8
Specifying Pattern SolutionsSpecifying Pattern Solutions
A pattern specification contains a A pattern specification contains a Structural Structural Pattern SpecificationPattern Specification (SPS) and a set of (SPS) and a set of Interaction Pattern SpecificationsInteraction Pattern Specifications (IPSs). (IPSs).
A UML model conforms to a pattern A UML model conforms to a pattern specification if its class diagram conforms to specification if its class diagram conforms to the SPS and the interactions described by the SPS and the interactions described by sequence diagrams conform to the IPSs.sequence diagrams conform to the IPSs.
9
Structural Pattern Specifications Structural Pattern Specifications A SPS defines the part of the pattern metamodel A SPS defines the part of the pattern metamodel
that characterizes class diagram views of pattern that characterizes class diagram views of pattern solutions.solutions.
An SPS consists of a structure of An SPS consists of a structure of pattern rolespattern roles (henceforth referred to as roles), where a role (henceforth referred to as roles), where a role specifies properties that a UML model element specifies properties that a UML model element must have if it is to be part of a pattern solution must have if it is to be part of a pattern solution model.model.
The metamodel class is called the The metamodel class is called the basebase of the role. of the role.
A role with a base A role with a base BB specifies a subset of specifies a subset of instances of the UML metamodel class instances of the UML metamodel class BB..
10
Structural Pattern Specifications Structural Pattern Specifications (cont’d)(cont’d)
A UML model element conforms to (or A UML model element conforms to (or plays) a role if it satisfies the properties plays) a role if it satisfies the properties defined in the role, that is, the element is an defined in the role, that is, the element is an instance of the subtype defined by the role.instance of the subtype defined by the role.
A role in an SPS can be classified as a A role in an SPS can be classified as a classifierclassifier or a or a relationshiprelationship role. role. A role that has the base A role that has the base ClassifierClassifier or a base that or a base that
is a subtype of is a subtype of ClassifierClassifier (e.g., (e.g., ClassClass, , InterfaceInterface) is ) is a classifier role.a classifier role.
A relationship role is any role that has the base A relationship role is any role that has the base RelationshipRelationship or a base that is a subtype of or a base that is a subtype of RelationshipRelationship (e.g., (e.g., AssociationAssociation, , GeneralizationGeneralization).).
11
The SPS NotationThe SPS Notation A classifier role is represented by a syntactic A classifier role is represented by a syntactic
variant of the UML class symbol.variant of the UML class symbol.
Structure of a classifier role.Structure of a classifier role.
A relationship role is represented by a syntactic A relationship role is represented by a syntactic variant of the UML association symbol.variant of the UML association symbol.
Well-formedness rules that cannot be expressed in Well-formedness rules that cannot be expressed in an SPS's role structure are expressed in the OCL an SPS's role structure are expressed in the OCL (Object Constraint Language).(Object Constraint Language).
12
An SPS ExampleAn SPS Example
A partial views of an SPS and its metamodelA partial views of an SPS and its metamodel
context Subject inv : self:isAbstract = falsecontext Sub inv : self:lowerBound() = 1self:upperBound() = 1context Obs inv : self:lowerBound() = 0
13
Establishing Structural Establishing Structural Conformance to an SPSConformance to an SPS
A class diagram structurally conforms to an A class diagram structurally conforms to an SPS, with respect to a binding of model SPS, with respect to a binding of model elements to roles, if it satisfies:elements to roles, if it satisfies: the structural constraints specified by the SPS the structural constraints specified by the SPS
role structurerole structure the metamodel-level constraintsthe metamodel-level constraints
14
Establishing Structural Conformance to Establishing Structural Conformance to an SPS (cont’d)an SPS (cont’d)
The following activities are carried out when The following activities are carried out when establishing that a class diagram establishing that a class diagram structurally conforms to an SPS:structurally conforms to an SPS: Bind models elements to rolesBind models elements to roles Check compliance with classifier role realization Check compliance with classifier role realization
multiplicitiesmultiplicities Establish structural conformance of classifiers to Establish structural conformance of classifiers to
their bound rolestheir bound roles Establish conformance of relationships to their Establish conformance of relationships to their
bound relationship rolesbound relationship roles
15
Establishing Structural Conformance to Establishing Structural Conformance to an SPS (cont’d)an SPS (cont’d)
An SPS and a structurally conforming class An SPS and a structurally conforming class diagram.diagram.
16
Establishing Structural Conformance to Establishing Structural Conformance to an SPS (cont’d)an SPS (cont’d)
A partial SPS for a variant of the Observer A partial SPS for a variant of the Observer pattern and a conforming class diagram.pattern and a conforming class diagram.
17
Specifying Semantic Pattern Specifying Semantic Pattern Properties in an SPSProperties in an SPS
The role structure and metamodel-level The role structure and metamodel-level constraints of an SPS determine the constraints of an SPS determine the syntactic structure of conforming class syntactic structure of conforming class diagrams.diagrams.
An operation template for the Attach An operation template for the Attach BehavioralFeature role is given below:BehavioralFeature role is given below:
context|Subject :: |Attach(|obsv : |Observer)
pre : true
post : self:|Obs = self:|Obs@pre including(|obsv)
18
Specifying Semantic Pattern Properties in an Specifying Semantic Pattern Properties in an SPS (cont’d)SPS (cont’d)
The Subject role is also associated with the The Subject role is also associated with the following BehavioralFeature roles:following BehavioralFeature roles: DetachDetach
specifies behaviors that remove observers from specifies behaviors that remove observers from subjectssubjects
SetStateSetState specifies behaviors that set the subject statespecifies behaviors that set the subject state
NotifyNotify specifies behaviors that notify observers specifies behaviors that notify observers
whenever a change in the subject state occurswhenever a change in the subject state occurs GetStateGetState
specifies behaviors that return the subject statespecifies behaviors that return the subject state
19
Specifying Semantic Pattern Properties in an Specifying Semantic Pattern Properties in an SPS (cont’d)SPS (cont’d)
context |Subject :: |Detach(|obsv : |Observer)pre : self.|Obs includes(|obsv)post : self.jObs = self.|Obs@pre excluding(|obsv)context jSubject :: |GetState() : |SubjStateTypepre : truepost : result = |SubjectState
context |Subject :: |SetState(|newState : |SubjStateType)pre : truepost : |SubjectState = |newState
context |Observer :: |Update(|subj : |Subject)pre : truepost : |ObserverState = |Function(|subj.|SubjectState)
20
Specifying Semantic Pattern Properties in an Specifying Semantic Pattern Properties in an SPS (cont’d)SPS (cont’d)
Constraint templates can also be used to Constraint templates can also be used to specify invariant properties in a UML model.specify invariant properties in a UML model.
These templates are referred to as These templates are referred to as property property templatestemplates..context |Subject
|Obs --> forAll(|ObserverState = |Function(|SubjectState)
21
Establishing Full Conformance to an Establishing Full Conformance to an SPSSPS
A class diagram fully conforms to an SPS, with A class diagram fully conforms to an SPS, with respect to a binding of model elements to roles, ifrespect to a binding of model elements to roles, if it structurally conforms to the SPSit structurally conforms to the SPS the semantic properties expressed by constraints in the semantic properties expressed by constraints in
the class diagrams (e.g., operation specifications and the class diagrams (e.g., operation specifications and class invariants) conform to the constraint templates in class invariants) conform to the constraint templates in the SPSthe SPS
Establishing that the semantic properties Establishing that the semantic properties expressed in a class diagram conform to expressed in a class diagram conform to constraint templates in an SPS involvesconstraint templates in an SPS involves instantiating the constraint templates using the role instantiating the constraint templates using the role
bindingsbindings establishing that the constraints given in the class establishing that the constraints given in the class
diagram refine the instantiations of the constraint diagram refine the instantiations of the constraint templatestemplates
22
Establishing Full Conformance to an Establishing Full Conformance to an SPS (cont’d)SPS (cont’d)
Establishing that an operation specification Establishing that an operation specification conforms to an operation template involves conforms to an operation template involves proving that the operation specification refines proving that the operation specification refines the operation template instantiation.the operation template instantiation.
Given an operation Given an operation OpOp with pre and with pre and postconditionspostconditions contextcontext Op(...) : Op(...) : prepre: preR; : preR; postpost: postR: postRand an instantiated operation template for a and an instantiated operation template for a feature role feature role ROpROp contextcontext ROp(...) : ROp(...) : prepre: preM; : preM; postpost: postM,: postM,Op is said to fully conform to ROp ifOp is said to fully conform to ROp if preM => preRpreM => preR (preM and postR) => postM(preM and postR) => postM
23
Interaction Pattern Specifications Interaction Pattern Specifications (IPSs)(IPSs)
An Interaction Pattern Specification (IPS) An Interaction Pattern Specification (IPS) describes a pattern of interactions and is describes a pattern of interactions and is defined in terms of roles defined in an SPS.defined in terms of roles defined in an SPS.
The SPS roles are used to specify The SPS roles are used to specify participants in an interaction pattern.participants in an interaction pattern.
24
Interaction Pattern Specifications Interaction Pattern Specifications (IPSs) (cont’d)(IPSs) (cont’d)
An IPS for an Observer pattern and a partial An IPS for an Observer pattern and a partial view of its specialized UML metamodel.view of its specialized UML metamodel.
25
Interaction Pattern Specifications Interaction Pattern Specifications (IPSs) (cont’d)(IPSs) (cont’d)
An IPS consists of an interaction role that An IPS consists of an interaction role that defines a specialization of the UML defines a specialization of the UML metamodel class Interaction.metamodel class Interaction.
An interaction role is a structure of lifeline An interaction role is a structure of lifeline and message roles.and message roles.
A message role is associated with a A message role is associated with a BehavioralFeature role: A conforming BehavioralFeature role: A conforming message specifies a call to an operation that message specifies a call to an operation that conforms to the BehavioralFeature role.conforms to the BehavioralFeature role.
26
Interaction Pattern Specifications Interaction Pattern Specifications (IPSs) (cont’d)(IPSs) (cont’d)
A sequence diagram that conforms to the A sequence diagram that conforms to the Observer IPSObserver IPS
27
Specifying Visitor Pattern SolutionsSpecifying Visitor Pattern Solutions
Visitor design pattern solution Visitor design pattern solution class class diagramdiagram
28
Specifying Visitor Pattern Solutions Specifying Visitor Pattern Solutions (cont’d)(cont’d)
Visitor design pattern solution Visitor design pattern solution sequence sequence diagramdiagram
29
A Visitor SPSA Visitor SPS The SPS contains two role hierarchiesThe SPS contains two role hierarchies
The The VisitorVisitor The The ElementElement
context | AbstractVisitor inv : self:oclIsTypeOf(Interface)
or (self:oclIsTypeOf(class) and self:isAbstract = true)
context | AbstractVisitor inv : self:oclIsTypeOf(Class)
and self:isAbstract = false
context | Obj inv : self:lowerBound() = 0
and self:upperBound() = 1
context | Elem inv : self:lowerBound() = 1
30
A Visitor SPS (cont’d)A Visitor SPS (cont’d)
A more complex Visitor conformant class A more complex Visitor conformant class diagramdiagram
31
An IPS for the Visitor PatternAn IPS for the Visitor Pattern
A Visitor IPSA Visitor IPS
32
A Composite Part StructureA Composite Part Structure
33
A Conforming Visitor Sequence A Conforming Visitor Sequence DiagramDiagram
34
An Analysis of Early ExperienceAn Analysis of Early Experience
The goal of author’s work is to create The goal of author’s work is to create practical pattern specification that supports practical pattern specification that supports the use of patterns.the use of patterns.
To achieve this goalTo achieve this goal
The advantage of using UML as syntactic The advantage of using UML as syntactic base for the pattern specificationbase for the pattern specification
Prototype tool for crating pattern Prototype tool for crating pattern specification on the top of the Rational Rose specification on the top of the Rational Rose tooltool
35
An Analysis of Early Experience An Analysis of Early Experience (cont’d)(cont’d)
Constraint templatesConstraint templates
The pattern specification language has been The pattern specification language has been used by graduate students to develop used by graduate students to develop specification of design pattern.specification of design pattern. Create specification for patterns that did not Create specification for patterns that did not
involve the use of recursion in the interaction involve the use of recursion in the interaction diagramdiagram
The use of the UML notation to express roles The use of the UML notation to express roles helped in communicating the conceptshelped in communicating the concepts
Modeled by state machines and activity diagramModeled by state machines and activity diagram
36
Related WorkRelated Work
Specifying design patternsSpecifying design patterns Formal specification techniquesFormal specification techniques Using graphical constraint diagramUsing graphical constraint diagram In terms of three layers of models: role-model, In terms of three layers of models: role-model,
type-model, and class-modeltype-model, and class-model UML metamodeling appproachUML metamodeling appproach
37
Conclusion and Further WorkConclusion and Further Work
The pattern specification technique The pattern specification technique described in this paper can be used as a described in this paper can be used as a base for tools that support creation and base for tools that support creation and evolution of patterns, and rigorous evolution of patterns, and rigorous application of design patterns to UML application of design patterns to UML models.models.
Specifying pattern solutions at the UML Specifying pattern solutions at the UML metamodel level allows tool developers to metamodel level allows tool developers to build support for creating patterns and for build support for creating patterns and for checking conformance to pattern checking conformance to pattern specifications.specifications.