modelling small programs modelling large programs modelling application frameworks modelling design...
TRANSCRIPT
Modelling small programs
Modelling large programs
Modelling application frameworks
Modelling design patterns
Object-Oriented Modellingin LePUS3 and Class-Z
1
Lecture notes in graduate module, CE839: Software Design and Architecture, Autumn term 2008/9Dr Amnon H Eden, School of Computer Science and Electronic Engineering, University of Essex
2
LePUS3 and Class-Z: desiderata Abstraction
Abstract ontology Offer an answer: What are the conceptual building blocks of software design?
Scaling: capture the building blocks of very large programs Detailed notation—cluttered diagrams What NOT to model? What a specification should NOT represent?
Rigour Formal specification Verification
Decidability: Tool support in “round-trip engineering” automated verification is possible in principle Tool support automates the verification process Allows us to “close the loop” of round-trip engineering
Visualization (Optional Offer a “picture” of a specification:
Existing program: a ‘roadmap’ to the millions of lines of code A design motif: design pattern, architectural style
Makes software easier to understand and change
Theory & practice Be relevant to practical applications Provide a sound foundation in a solid mathematical theory
3
Specification language: desiderata(cont.) Combine theory & practice
It has long been my personal view that the separation of practical and theoretical work is artificial and injurious. Much of the practical work done in computing, both in software and in hardware design, is unsound and clumsy because the people who do it have not any clear understanding of the fundamental design principles of their work. Most of the abstract mathematical and theoretical work is sterile because it has no point of contact with real computing. -- Christopher Strachey
Iterators
Aggregates
createIterator
next
Elements
Produce
AggregateReturn
4
What can be modelled in LePUS3/Class-Z?
(Collections in java.util)
Programs
(Java Servlets)
Application frameworks
(The Iterator pattern)
Design patterns
httpServlet
Inhe
rit
A
servletOps
userServlet
servletOps
For
war
d
Col l ecti onsHrc
I teratorsHrc
obj ect
newI tr
next
Produce
Aggregate Return
5
What cannot be modelled in LePUS3/Class-Z? Temporal relations
‘Method x should be called before method y’ No collaboration/interaction diagrams, flow charts,
statecharts, … Statements about specific objects
Strategic design Architectural styles Components
Programs in procedural/functional/other programming paradigms LePUS3 and Class-Z model object-oriented programs
Tool support in LePUS3and Class-Z
Design
Iterators
Aggregates
createIterator
next
Elements
Produce
AggregateReturn
interface Collection ... { public Iterator iterator() { ... }}
interface Collection ... { public Iterator iterator() { ... }}public class LinkedList ... { public Iterator iterator() { ... }}
public class LinkedList ... { public Iterator iterator() { ... }}
Formal specificationSoftware modellingSoftware visualization
Reverse engineering(Design Recovery)
Forward engineering (Verification)
ApplicationsApp. frameworksClass libraries
Implementation
7
LePUS3 vs. Class-Z
Specifications can be expressed in one of two ways: LePUS3: Visual, similar to UML Class Diagrams
Class-Z: symbolic, similar to Z
Students are only required to learn one of the notations
printStreamjava.lang.System Member
java.lang.system, printStream :
Example
Member(java.lang.system,printStream)
LePUS3
Class-Z
The genealogy of LePUS3 and Class-Z Definition: As a subset of first-order predicate
calculus (classical logic) Official reference manual:
A.H. Eden, E. Gasparis, J. Nicholson. "LePUS3 and Class-Z Reference Manual". University of Essex, Tech. Rep. CSM-474, ISSN 1744-8050 (2007). http://lepus.org.uk/ref/refman/refman.xml
Historical roots: LePUS3: LePUS [Eden 2001]—LanguagE for Pattern
Uniform Specification Class-Z: Z [Spivey]
8
9
Modelling small programsin LePUS3 and Class-Z
Class and signature constants
Unary relation symbols
Binary relation symbols
Modelling individual classes
class constant: represents any specific static type such as a class, Java interface, and primitive types
col l ecti onl i nkedLi st i nt
linkedList, collection, int :
Example
class LinkedLi
st
interfaceCollecti
on
primitive typeint
10
Modelling individual methods
signature constant: represents a specific ‘signature’ of (one or more) methods
11
linkedList
newItr
collection
newItr
A method with signature newItr is defined in class Collection
A method with signature newItr is defined in class LinkedList
linkedList, collection : newItr :
Example
Method(newItrlinkedList)Method(newItrcollection)
public class LinkedList ... { public Iterator newItr() { ... }}public class Collection ... { public Iterator newItr() { ... }}
public class LinkedList ... { public Iterator newItr() { ... }}public class Collection ... { public Iterator newItr() { ... }}
Modelling properties
Unary relation: represents a property
12
Class AbstractSet is abstract
abstractSet, collection : newItr :
Example
Abstract(abstractSet)Abstract(collection)Abstract(newItrcollection)
col l ecti on
newI tr
AbstractAbstract
Collection.newItr is an abstract method
Collection is an Interface
13
Modelling relations between individuals Binary relation: represents a relation between two
individuals
linkedList, abstractSet, ListItr, ListIterator :
Example
Inherit(linkedList,abstractSet)Inherit(ListItr,ListIterator)
abstractSetlinkedList InheritListIteratorListIter
Inherit
LinkedList ‘extends’ AbstractSet
ListIter ‘implements’ ListIterator
14
Binary relations: Member
public class System {... public static PrintStream out;...}
public class System {... public static PrintStream out;...}
printStreamjava.lang.System Member
java.lang.system, printStream :
Example
Member(java.lang.system,printStream)
Binary relations: Aggregate
obj ectl i nkedLi stAggregate
linkedList, object :
Example
Aggregate(linkedList,object)
15
Binary relations: Call
Note that the Call relation abstracts away all information about the control-flow
16
public class Test { public static void main(String[] args) { if (args.length == 0) System.out.print("Insufficient arguments"); ...
public class Test { public static void main(String[] args) { if (args.length == 0) System.out.print("Insufficient arguments"); ...
test, printStream : main, print :
Example
Call(maintest, printprintStream)
test
main
printStream
Callprint
17
public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest rq, HttpServletResponse rs) { super.doGet(rq,rs); }
public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest rq, HttpServletResponse rs) { super.doGet(rq,rs); }
Binary relations: Forward
Method MyServlet.doGet forwards the call to HttpServlet.doGet
myServlet, httpServlet : doGet :
Example
Forward(doGetmyServlet, doGethttpServlet)
myServlet
doGet
httpServlet
ForwarddoGet
Forward: A special kind of a Call relation in which the formal arguments are passed on to a method withsame signature
18
public class MyClass { public void method() { ... if ... else ... ... for (int index = 0; ...) ... }...}
public class MyClass { public void method() { ... if ... else ... ... for (int index = 0; ...) ... }...}
Binary relations: Create
myCl ass
methodi nt
Create
Method MyClass.method may create an integer
linkedList, listItr : listIterator :
Example
Produce(listIteratorlinkedList, listItr)
19
public class LinkedList { ... public ListIterator listIterator(int index) { if (1 < 0)
return new ListItr(index); } ...}
public class LinkedList { ... public ListIterator listIterator(int index) { if (1 < 0)
return new ListItr(index); } ...}
Binary relations: Produce
linkedList
listIteratorlistItr
Produce
Method LinkedList.listIterator may create and return a new ListItr
linkedList, listItr : listIterator :
Example
Produce(listIteratorlinkedList, listItr)
Produce: A special kind of a Create relation in which the new object is returned(typical to ‘factory methods’)
Modelling indirect relations
Transitive relation: represents possibly indirect relation (the ‘transitive closure’ of a binary relation)
20
collectionlinkedList Inherit+
interface Collection { ...
class AbstractList implements Collection {...
class AbstractSet extends AbstractList ...
class LinkedList extends AbstractSet ...
interface Collection { ...
class AbstractList implements Collection {...
class AbstractSet extends AbstractList ...
class LinkedList extends AbstractSet ...
linkedList, collection :
Example
Inherit+(linkedList, collection)
21
Transitive relations II
public class FileInputStream ... { public int read(byte[] b) throws IOException, NullPointerException { ...
public class FileInputStream ... { public int read(byte[] b) throws IOException, NullPointerException { ...
fileInputStream, ioException, nullPointerException : read,nullPointerException,ioException :
Example
Call+(readfileInputStream, ioExceptionioException)Call+(readfileInputStream, nullPointerExceptionnullPointerException)
Call+
Call+
nullPointerException
ioExceptionfileInputStream
read
ioException
nullPointerException
22
Case Study I: LinkedList and ListItr
LinkedList
newItr()
return new ListItr(); Object
Collection
newItr()
Iterator
next()
ListItr
next()
LePUS3 UML Class diagram
l i nkedLi st.l i st I tr
l i nkedLi st
col l ecti on i teratorAbstract Abstract
obj ect
newI trnext
newI trnext
Produce
Return
AbstractAbstract
Aggregate
Inherit+ Inherit+
23
Case Study II: java.io.XXReader classes
l i neNumberReader
buff eredReader
read
read
mark
mark
reset
reset
Forward Forward Forward
23
bufferedReader, lineNumberReader : read, mark, reset :
ReaderExample
public class LineNumberReader extends BufferedReader { … public void read() { … super.read(); … } … public void mark(int readAheadLimit) { … super.mark(readAheadLimit); … } … public void reset() { … super.reset(); … } …
public class LineNumberReader extends BufferedReader { … public void read() { … super.read(); … } … public void mark(int readAheadLimit) { … super.mark(readAheadLimit); … } … public void reset() { … super.reset(); … } …
Forward(readlineNumberReader, readbufferedReader)Forward(marklineNumberReader, markbufferedReader)Forward(resetlineNumberReader, resetbufferedReader)
24
Exercise
“Translate” the LePUS3 chart in the case study into a Class-Z specification
Use either Class-Z or LePUS to model three DIFFERENT specifications of the classes Collection, Iterator, LinkedList, and ListItr in the package java.util. Each specification should include one or more of the methods
defined in these classes. Which ones did you choose to model and why?
Note that each specification may contain a different set of relations
Note that each specification must be SATISFIED by the classes in java.util!
25
Exercise (Cont.)
Which one is the most correct description of the purpose of a LePUS/Class-Z specification?
1. Each specification is model of a particular implementation
2. Each specification models an one or more possible implementations
3. Each specification models an aspect of one implementation abstracted for a particular purpose
4. Each specification models an aspect of one or more possible implementations abstracted for a particular purpose
Exercise (Cont.)
How many ways can you model a Java program in which class MyClass has a method therein with the signature method(String arg) which throws an exception of class MyException in LePUS3 or Class-Z?
26
27
Modelling large programsin LePUS3 and Class-Z
Hierarchy constant
1-dim class and signature constants
Total and Isomorphic predicates
Modelling sets of classes
1-dimensional class constant: Stands for a (non-empty) set of specific static types
28
ConcreteCollections :
Example
treeSet
hashSet
linkedList
arrayList
ConcreteCol l ecti ons
Modelling sets of methods (one signature)
Clan: A set of methods with same signaturetreeSet
newItr
hashSet
newItr
linkedList
newItr
arrayList
newItr
Concretecollections
newItr
ConcreteCollections : newItr :
Example
All(Method, newItrConcreteCollections)29
Modelling sets of methods (many signatures)
30
1-DimSignatureConstant :
Example
1-dimensional signature constant: Stands for a (non-empty) set of specific method signatures
1-Di m Si gnatureConstant
si g1 si gn
Modelling sets of methods (many signatures) Tribe: A set of methods in same class
31
httpServlet
doGetdoPost
doPutdoTrace
httpServlet
ServletOps
httpServlet : ServletOps :
Example
All(Method, ServletOpshttpServlet)
Modelling sets of methods (many signatures): example
32
buff eredReader
read mark reset
buff eredReader
Buff erOps
BufferOps : bufferedReader :
Example
All(Method, BufferOps bufferedReader)
33
Modelling relations between sets: Total
Domai n BinaryRelation
Range
d1 r1
d2 r2
d3 r3
d4
BinaryRelation
BinaryRelationEvery element in Domain is in relation
Relation with some element in Range
Total(BinaryRelation,Domain,Range)
34
Total predicate: exampleIn
heri
t+ Inhe
rit+
collection
Inhe
rit+ In
heri
t+
treeSet
hashSet
linkedList
arrayList
collection
ConcreteCollections
Inhe
rit+
ConcreteCollections : collection :
Example
Total(Inherit+,ConcreteCollections,collection)
Total predicate: example II
ConcreteCollections : object :
Example
Total(Aggregate,ConcreteCollections,object)
treeSet
hashSet
l i nkedLi st
arrayLi st
obj ect
Aggregate
Aggregate
Aggregate
Aggregate
ConcreteCol l ecti ons
obj ect
Aggregate
35
36
Modelling relations between sets: Isomorphic
Every element in Domain is in relation BinaryRelationwith a unique element in Range
Isomorphic(BinaryRelation,Domain,Range)
Domai n RangeBinary
Relation
d1 r1
d2 r2
d3 r3
d4Abstract
BinaryRelation
Abstract
r4
BinaryRelation
BinaryRelation
Isomorphic predicate: example I
bufferedReader, lineNumberReader : BufferOps :
Example
Inherit(lineNumberReader,bufferedReader)Isomorphic(Forward, ServletOpslineNumberReader,ServletOpsbufferedReader)
l i neNumberReader
buff eredReader
read
read
mark
mark
reset
reset
Forward Forward Forward
buff eredReader
l i neNumberReader
Buff erOps
Buff erOps
Forward
37
Isomorphic predicate: example
II
Forward
Forward
Forward
j ava. awt.component
addPropertyChange
Li stener
appl yComponent
Ori entati on
transferFocus
Backward
j ava. awt.contai ner
addPropertyChange
Li stener
appl yComponent
Ori entati on
transferFocus
Backward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
Forward
nextFocusHel per
nextFocusHel per
i sFocusCycl eRoot
i sFocusCycl eRoot
getMaxi mumSi ze
preferredSi ze
getMaxi mumSi ze
preferredSi ze
removeNoti f y
removeNoti f y
getAl i gnmentX
getAl i gnmentX
di spatchEventI mpl
di spatchEventI mpl
processEvent
processEvent
eventEnabl ed
eventEnabl ed
l i ghtwei ghtPri nt
l i ghtwei ghtPri nt
l i ghtwei ghtPai nt
l i ghtwei ghtPai nt
numLi steni ng
numLi steni ng
getAl i gnmentY
getAl i gnmentY
addNoti f yaddNoti f y
l i stl i st
mi ni mumSi zemi ni mumSi ze
paramStri ngparamStri ng
setFontsetFont
i nval i datei nval i date
pri ntpri nt
j ava. awt.contai ner
j ava. awt.component
Contai nerOps
Contai nerOpsForward
38
Case study: collections & iterators in java.util
treeSet treeMap.KeyI terator
hashSet
l i nkedLi st l i nkedLi st.Li stI tr
arrayLi st abstractLi st . I tr
hashMap.KeyI terator
newI tr
newI tr
newI tr
newI tr Produce
Produce
Produce
Produce
ConcreteCol l ecti ons Concrete
I teratorsnewI tr Produce
ConcreteCollections, ConcreteIterators : Isomorphic(Produce, newItrConcreteCollections, ConcreteIterators)
Example
39
ConcreteI terators
ConcreteCol l ecti ons
col l ecti on i teratorAbstract Abstract
obj ect
newI trnext
newI trnext
Return
AbstractAbstract
Aggregate
Inherit+ Inherit+
Produce
40
Collections & iterators in java.util (cont.)
treeSet
col l ecti on i terator
treeMap.KeyI terator
hashSet
l i nkedLi st l i nkedLi st.Li st I tr
arrayLi st
abstractLi st . I tr
hashMap.KeyI terator
Abstract Abstract
obj ect
newI trnext
newI trnext
newI tr
newI trnext
newI trnext
next
Inherit+
Produce
Inherit+
Produce
Produce
Produce
Inherit+
Inherit+
Return
Return
ReturnReturn
AbstractAbstract
Aggregate
Aggregate
Aggregate
Aggregate
Inherit+
Inherit+
Inherit+
Inherit+
Exercise
Translate the specification of collections and iterators to UML
41
Modelling class hierarchies
1-dimensional hierarchy constant: a set of classes s.t. all inherit from one
42
Hierarchy :
Example
1-Di m Hi erarchy Constant
OtherCl asses
rootCl s
Inherit+
Hierarchy: example
43
treeSet
col l ecti on
hashSet
l i nkedLi st
arrayLi st
Inherit+
Inherit+
Inherit+
Inherit+
Col l ecti onsHrc
CollectionsHrc :
Example
Modelling sets of methods revisited
44
OtherCl asses
rootCl s
si gHrc
Inherit+si g
si g
Hrc : sig :
Example
All(Method,sigHrc)
45
Example: the Lists hierarchy
Lists : add :
Example
All(Method,addLists)
arrayLi st
vector
l i st
l i nkedLi st abstractLi st
Abstract
Abstract
addadd
add
add add
Inherit
Inherit Inherit
Inherit
Li stsHrc
add
46
Case study: collections & iterators in java.util
CollectionsHrc, IteratorsHrc : next, newItr : object :
Example
Isomorphic(Produce, newItrCollectionsHrc, IteratorsHrc)Total(Return, nextIteratorsHrc, object)Total(Aggregate, CollectionsHrc, IteratorsHrc)
ConcreteI terators
ConcreteCol l ecti ons
col l ecti on i teratorAbstract Abstract
obj ect
newI trnext
newI trnext
Return
AbstractAbstract
Aggregate
Inherit+ Inherit+
Produce
Col l ecti onsHrc
I teratorsHrc
obj ect
newI tr
next
Produce
Aggregate Return
47
Example: lists, sets, and sorted sets
Lists, Sets, SortedSets : newItr : collection :
Example
Total(Inherit+, Lists, collection)Total(Inherit+, Sets, collection)Total(Inherit+, SortedSets, collection)Method(newItrcollection)All(Method, newItrLists)All(Method, newItrSets)All(Method, newItrSortedSets)
Inhe
rit+
col l ecti on
Sets
newI tr
Li sts
newI tr
SortedSets
newI tr
Inhe
rit+ Inherit +
newI tr
48
Modelling application frameworks
Variables
49
Variables vs. constants
ObjectaClass
aClass, Object :
Example
A class variable A class constant
50
Variables vs. constants II
abstractSetlinkedList Inherit
LinkedList extends/ implements AbstractSet
yx Inherit
Class x extends/implements class y
linkedList, abstractSet, x, y :
Example
Inherit(linkedList,abstractSet)Inherit(x,y)
51
Assignments
A specification with variables is only meaningful wrt a specific assignment
Example: Assignment-1 x is assigned to LinkedList y is assigned to AbstractSet
Example: Assignment-2 y is assigned to LinkedList x is assigned to AbstractSet
Assignment-1 is satisfied by java.util Assignment-2 is satisfied by java.uti
yx Inherit
x, y :
Example
Inherit(x,y)
52
httpServlet
Inhe
rit
A
ServletOps
userServlet
ServletOps
For
war
d
Example: Java Servlets
Servlet class must extend class HTTPServlet
Servlet class must override a particular set of methods
Each method in your Servlet must forward call to respective method in superclass
Servlet class can be any classthat satisfies therelations
httpServlet, userServlet : ServletOps : ()
JavaServlet
Isomorphic(Forward, ServletOpsuserServlet, ServletOpshttpServlet)Inherit(userServlet, httpServlet)
53
Variables vs. constants: example I
httpServlet
Inhe
rit
A
doGet
userServlet
doGet
For
war
d
public class HelloText extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { super.doGet(request,response); response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("Hello World"); }}
public class HelloText extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { super.doGet(request,response); response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("Hello World"); }}
httpServlet
Inhe
rit
A
doGet
HelloText
doGet
For
war
d
A specific implementation Any Java Servlet
54
Variables vs. constants: example II
Iterator pattern
Collections, Iterators : next, newItr : object :
CollectionsInJavaUtil
Isomorphic(Produce, newItrCollections, Iterators)Return(nextIterators, object)
Collections in java.util
Iterator
AggregatesIteratorscreateIteratornextobject
Isomorphic(ProducecreateIteratorAggregatesIteratorsReturnnextIteratorsobject
Iterators
Aggregates
createIterator
next
Elements
Produce
AggregateReturn
Col l ecti onsHrc
I teratorsHrc
obj ect
newI tr
next
Produce
Aggregate Return
Variables vs. constants: example III
Composite patternComposite in java.awt
component
compositeLeaves
ComponentOps
CompositeOps
ComponentOps
Abstract
ComponentOps
Inherit
Forward
AggregateInherit
ComponentLeaves
ComponentOps
contai ner
ComponentOps
Composi teOps
component
ComponentOps
Forward
Abstract
Inherit InheritAggregate
55
56
Case study: Enterprise JavaBeansFrom [Monson-Haefel 2001]:
1. “Every bean [class] obtains an EJBContext object, which is a reference to the container
2. “The home interface extends the ...javax.ejb.EJBHome interface
3. “A home [interface] may have many create() methods, … , each of which must have corresponding ejbCreate() and ejbPostCreate() methods in the bean class. The number and datatype of the arguments of each create() are left up to the bean developer”
4. “When a create() method is invoked on the home interface, the container delegates the invocation to the corresponding ejbCreate() and ejbPostCreate() methods on the bean class.
5. [An implementation for the bean’s home interface is generated by the container.]”
57
Modelling Enterprise JavaBeans I
Bean
EJ BContext
A
Mem
ber
j avax. ej b.EJ BHome
A
BeanHomeInterfaceA
Inhe
rit
create
“Every bean [class] obtains
an EJBContext object,
which is a reference to the
container”
“The home interface extends
the ...javax.ejb.EJBHome
interface”
BeanHomeImp
Beancreate
Call
ejbPostCreateCall
ejbCreate
58
Modelling Enterprise JavaBeans II
“A home [interface] may have many create() methods, … , each of which must have corresponding ejbCreate() and ejbPostCreate() methods in the bean class. The number and datatype of the arguments of each create() are left up to the bean developer
“When a create() method is invoked on the home interface, the container delegates the invocation to the corresponding ejbCreate() and ejbPostCreate() methods on the bean class”
59
Summary: Enterprise JavaBeans
j avax. ej b.EJ BHome
A
BeanHomeInterfaceA
Inhe
rit
create
BeanHomeImp
GeneratedFrom
Bean
EJ BContext
A
Mem
ber
create
Call
ejbPostCreateCall
ejbCreate
60
Modelling design patterns
The ‘gang of four’ patterns:Iterator, Proxy, Composite, Observer,
Factory Method, Adapter (Object), Adapter (Class), Strategy
61
Iterator pattern
Iterator
AggregatesIteratorscreateIteratornextElements
Isomorphic(ProducecreateIteratorAggregatesIteratorsTotalReturnnextIteratorsElementsTotalAggregateAggregatesElements
Iterators
Aggregates
createIterator
next
Elements
Produce
AggregateReturn
62
Proxy pattern
Proxy
clientsubjectproxyrealSubjectOps-1Ops-2LocalRequestsRemoteRequests
AbstractsubjectTotal(CallOps-1clientLocalRequestssubjectTotal(Call, Ops-2ClientRemoteRequestssubjectTotal(CallRemoteRequestsproxyRemoteRequestsrealSubjectMethod(LocalRequestsproxy)MemberproxyrealSubjectInheritproxysubjectInheritrealSubjectsubject
client subject
Call
LocalRequests
RemoteRequests
CallOps-1
Ops-2
realSubject
RemoteRequests
proxy
Inherit
Member
LocalRequests
Inhe
rit
RemoteRequests Call
A
63
Composite pattern
Composite
componentcompositeLeavesCompositeOpsComponentOps
AbstractcomponentAll(MethodComponentOpsLeavesAll(MethodCompositeOpscompositeInheritcompositecomponentTotal(InheritLeavescomponentAggregate(compositecomponentIsomorphic(Forward,ComponentOpscompositeComponentOpscomponent
component
compositeLeaves
ComponentOps
CompositeOps
ComponentOps
Abstract
ComponentOps
Inherit
Forward
AggregateInherit
64
subject
Observers
Members
Inhe
rit
Call
A
concreteSubject
update(subject)
notify
SetState Call
getState
attach(Observers)
constructorCall
Cal
l
detach(Observers) Call
destructor
Observer pattern
Observer
subjectconcreteSubjectnotifygetStateupdateattachdetachconstructordestructorSetStateObservers
AbstractsubjectInheritconcreteSubjectsubjectTotal(CallSetStateconcreteSubjectnotifysubjectTotal(CallnotifysubjectupdateObserversTotal(CallupdateObserversgetStateconcreteSubjectTotal(CallconstructorObserversattachsubjectTotal(CalldestructorObserversdetachsubjectMemberssubjectObservers
65
Factory Method pattern
FactoryMethod
FactoriesProductsfactoryMethod
Isomorphic(ProducefactoryMethodFactoriesProducts
ProductsFactories
factoryMethod
Produce
66
Adapter (Class) pattern
ClassAdapter
clienttargetadapteradapteeOperationsRequestsSpecificRequests
AbstracttargetTotal(CallOperationsclientRequeststargetTotal(CallRequestsadapterSpecificRequestsadapteeInheritadaptertargetInheritadapteradaptee
Call
Inherit
targetclient
adaptee
adapter
Operations Requests
Requests
SpecificRequests
Abstract
Call
Inherit
67
Adapter (Object) pattern
ObjectAdapter
clienttargetadapteradapteeOperationsRequestsSpecificRequests
AbstracttargetTotal(CallOperationsclientRequeststargetTotal(CallRequestsadapterSpecificRequestsadapteeInheritadaptertargetMemberadapteradaptee
Call
Inherit Member
targetclient
adaptee
adapter
Operations Requests
Requests
SpecificRequests
Abstract
Call
68
Strategy pattern
Strategy
clientcontextrequestalgorithmInterfaceStrategies
MembercontextStrategiesCallrequestclientrequestcontextCallrequestcontextalgorithmStrategiesTotal(CallalgorithmStrategiesInterfacecontext
Strategies
context
client
Interface
algorithm(context)
request request Call
Call
Member
Call
Tool support in LePUS3 and Class-Z
69
Two-TierProgramming
Design
Iterators
Aggregates
createIterator
next
Elements
Produce
AggregateReturn
interface Collection ... { public Iterator iterator() { ... }}
interface Collection ... { public Iterator iterator() { ... }}public class LinkedList ... { public Iterator iterator() { ... }}
public class LinkedList ... { public Iterator iterator() { ... }}
Formal specificationSoftware modellingSoftware visualization
Reverse engineering(Design Recovery)
Forward engineering (Verification)
ApplicationsApp. frameworksClass libraries
Implementation
The Two-Tier Programming Toolkit Round-trip engineering Supports:
Specification & verification (forward engineering) Visualization (reverse engineering)
http://ttp.essex.ac.uk
71
The TTP Toolkit (cont.):Specification in LePUS3
72
The TTP Toolkit (cont.):Specification in Class-Z
73
The TTP Toolkit (cont.): Verification
74
The TTP Toolkit (cont.): Visualization
75
76
Exercises
1. Summarize the differences between LePUS3/Class-Z and UML:
1.1 Compare the LePUS3 chart with the UML Class diagram of LinkedList and the ListItr classes
1.2 Use UML to model the Collection and the Iterator hierarchies in Java.util. How is this diagram different from the LePUS3/Class-Z specification?
1.3 Use UML to model Java Servlets. How is this diagram different from the LePUS3/Class-Z specification?
1.4 Use UML to model one of the design patterns. How is this diagram different from the LePUS3/Class-Z specification?
2. List four abstraction mechanisms in LePUS3/Class-Z
Exercises (cont.)
3. Compare the LePUS3/Class-Z Specification of each one of the design patterns to the description in Gamma et al. 1995
3.1 What is the book saying that the chart/schema does not say?
3.2 What is the chart/schema saying that the book does not say?
3.3 What are the advantages of the book over the chart?
3.4 What are the advantages of the chart over the book?
77
Exercises (cont.)
4. Specify in LePUS3/Class-Z the following statements:
4.1 “There exists a method in class MyClass which creates instances of class String”
Answer:
78
myCl assx Create
stri ng
LePUS3 quick reference
constants and variables
79
0-dimclass
variable
1-DimClass
Variable
1-DimSignatureVariable
0-dimsignaturevariable
2-DIMHIERARCHYVARIABLE
1-DimHierarchyVariable
2-DI MHI ERARCHYCONSTANT
0-di mcl ass
constant
1-Di mCl ass
Constant
s-di msi gnatureconstant
1-Di mSi gnatureConstant
1-Di m Hi erarchy Constant
LePUS3 quick reference (cont.)Methods Relations and predicates
80
An individual method
A set of methodsof different
signature
Cl asses
si gHrc
si g
cl s
Si gnatures
cl s
si g
A set of methodsof same
signature
Isomorphicpredicate
Totalpredicate
UnaryRelation BinaryRelation
Domai n RangeBinary
Relation
Domai n RangeBinary
Relation
References Legend: Key to LePUS3 and Class-Z Symbols [.pdf]
<http://www.lepus.org.uk/ref/legend/legend.xml>
A.H. Eden, J. Nicholson. Object-oriented modelling: Theory and Practice. Unpublished manuscript (ask me for a copy)
A.H. Eden, E. Gasparis, J. Nicholson. "LePUS3 and Class-Z Reference Manual". University of Essex, Tech. Rep. CSM-474, ISSN 1744-8050 (2007). <http://lepus.org.uk/ref/refman/refman.xml>
A.H. Eden, E. Gasparis, J. Nicholson. "The 'Gang of Four' Companion: Formal specification of design patterns in LePUS3 and Class-Z.“ University of Essex, Tech. Rep. CSM-472, ISSN 1744-8050 (2007). <http://lepus.org.uk/ref/companion/index.xml>
A.H. Eden. “Formal Specification of Object-Oriented Design.” Proc. Int'l Conf. Multidisciplinary Design in Engineering CSME-MDE 2001 (21–22 Nov. 2001), Montreal, Canada.
81