1 formal specification of object-oriented design amnon h. eden department of computer science,...

42
1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department of Computer Science, University of Essex 25 October, 2003

Upload: marcia-wilkins

Post on 12-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

1

Formal Specification of

Object-Oriented Design

Amnon H. EdenDepartment of Computer Science, University of Essex

Research seminar given at the Department of Computer Science, University of

Essex

25 October, 2003

Page 2: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

2

Context

AbstractionsDesign Vs. Architecture

Page 3: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

3

Levels of Abstraction

Architecture

Design

Implementation

while (true) doc := c - 1;d := d + 1;if c < 0 goto continue;

continue: ...

while (true) doc := c - 1;d := d + 1;if c < 0 goto continue;

continue: ...

Page 4: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

4

Software ArchitectureAn emerging discipline

Origins: Perry & Wolf [92]

“Architectural Styles”: Shaw & Garlan [96]

Underlying formalisms Statecharts finite automata CSP

Architecture Description Languages (ADLs) ACME Rapide UniCon Wright, …

Page 5: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

5

Implementations Programming languages Denotational/operational semantics Computational models

Turing machine, RAM machine, Abstract State Machines

Formal Languages Lambda calculus, sigma calculus, …

Page 6: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

6

(Object-Oriented) Design Design Methodologies Notations Heuristics Design patterns

In particular: Gamma, Helm, Johnson & Vlissides [94]

Formalization?

Page 7: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

7

Objectives Conceptual:

1. A formal ontology for OOD2. A formal specification language

Patterns Libraries & frameworks

3. Elegance4. Reasoning capabilities

Pragmatic Full integration with existing programming practice Tool support Visual specifications

Page 8: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

8

Design Models

A Computational Model

Page 9: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

9

Program & Design Model

class PMButton {}class WinButton {}

void exit() {}

class PMButton {}class WinButton {}

void exit() {}

interface Creator {}

class WinCreator: extends Creator {WinButton_FactoryMethod() {

// Creation:new WinButton;// Invocation: exit();

}}

interface Creator {}

class WinCreator: extends Creator {WinButton_FactoryMethod() {

// Creation:new WinButton;// Invocation: exit();

}}

class PMCreator: extends Creator {PMButton_FactoryMethod() {

// ...new PMButton;

}}

class PMCreator: extends Creator {PMButton_FactoryMethod() {

// ...new PMButton;

}}

PM-creator

Win-creator

Win-button

Win-button-factory-method

exit

PM-button-factory-method

defined-in

defined-in

creator

PM-button

A

Page 10: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

10

Denotation Function

Given L OOPL, A Denotation: Modelling function

D : L UniverseD , RelationsD

Methods

Invoke

Create

Inherit

Classes

Classes, methods Abstract, Inherit,Create, Call, …

Page 11: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

11

Axiomatic Semantics

Building Blocks of O-O Design

Page 12: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

12

Hierarchy

AbstractFactory ConcreteFactories P()Abstract(AbstractFactory)Inherit(ConcreteFactories,AbstractFactory)

AbastractFactory

ConcreteFactories

A

Factories

Factories

Page 13: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

13

Clans, Selection Operator

PrimitiveOperations1 Classes P()PrimitiveOperation1ClassesClasses

PrimitiveOperation1

Page 14: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

14

Isomorphic Relations

Factories

CreateProductA

ProductA

Create Factories, ProductA

CreateProductA Create(CreateProductAProducts,

ProductA)

Page 15: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

15

LePUS

TermsPredicatesOperator

Page 16: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

16

Terms Constants: Belong to a given domain

EJBContext

Variables: Range over a given domainbean

Page 17: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

17 / SameSignature

barx

foo(int)

A::foo(int)

B::foo(int)A::bar()X

A::bar()X

Auxiliary Domains P(X) Power set of X

P(X) {x | x X }

Domain of all hierarchies {h P() | Hierarchy(h)}

Domain of function signatures

Page 18: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

18

PredicatesR(S,T) Total(R,S,T)

sS tT R(s,t)R(S,T) Isomorphic(R,S,T)

sS tT R(s,t) tT sS R(s,t)

Hierarchy(h) Abstract(r) ch, cr Inherit+(c,r)

Clan(F,C) DefinedIn(F,C) f1,f2F SameSignature(f1,f2)

Tribe(F,C) fF Tribe(f,C)

Page 19: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

19

Selection Operator Given a signature s, set of signatures S:

sC Selects methods in cC with signature s Result is a clan

SC Selects clans in cC with signature s Result is a tribe

Page 20: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

20

Specifications in LePUS

Design PatternsObject-Oriented Design

Page 21: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

21

Factory-Method Pattern

ProductsCreators

factory-methods

ProductsProducts, Creators : FactoryMethods :

Produce(FactoryMethodsCreators,Products)Return(FactoryMethodsCreators,Products)

Page 22: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

22

Observer Pattern

subject

Observers

Update(subject)concrete-

subject

getState

SetState

attach(observers)

notifyReferenceToMany(subject,Observers)Inherit(subject, concrete-subject)FirstArg(attach,observers)FirstArg(detach,observers)FirstArgupdateobservers,subject)Invoke(SetStateconcrete-observer, notifysubject)Invoke(notifysubject,updateObervers)Invoke(updateObervers,attachsubject)Invoke(updateObervers,detachsubject)Assign(attachsubject,sybject,observers)

subject, concrete-subject : observers : attach, detach, notify, update, get-state : SetState : P()

Page 23: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

23

Visitor Pattern

Visitors

Visit(Elements)

Elements

accept(Visitors)

Concision: Three isomorphic relations, one total relation,

and many pages of documentation in one

diagram

FirstArg(AcceptElements,Visitors)FirstArg(VisitVisitors,Elements)Invocation(AcceptElements,VisitVisitors)Invocation(VisitVisitors,Elements)

Elements, Visitors : Accept : Visit : P()

Page 24: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

24

DocumentationTaken from the description of the Enterprise JavaBeans™:

“Every bean obtains an EJBContext object, which is a reference directly to the container”

“A bean's home interface may declare zero or more create() methods, each of which must have corresponding ejbCreate() and ejbPostCreate() methods in the bean class. ”

Bean EJB Context

I

BeanHomeImp

Create Bean

G

ejbCreate

ejbPostCreate

BeanHomeInterface

ICreate Bean

Page 25: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

25

Enterprise JavaBeans™

java.ejb.EJBObject

Bean

BeanInterface

IMethods

EJBContext

setEntityContext

BeanStub

Methods G

Rem

ote

Methods

I

BeanSkeleton

Methods G

I

Clients

Methods

Page 26: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

26

Reasoning

Page 27: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

27

Conformance (also Refinement)

observer

observable

I

Viewsupdate

(Observable)

addObserver(Observer)

notifyObservers

setChanged

ctors

model

Accessors

Mutators

update(Observable)

subject

Observers

Update(subject)concrete-

subject

getState

SetState

attach(observers)

notify

“Model-View-Controller” in Java Swing

... Conforms to the Observer pattern

Page 28: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

28

creator, product : factory-method : Create(factory-methodfactory, product)Return(factory-methodfactory, product)

Projection

product

factoryfactory-method

product

factoryfactory-method

creator, product : P()factory-method : Create(factory-methodfactory, product)Return(factory-methodfactory, product)

Page 29: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

29

ProductsCreators

factory-methods

Products

Creators

Factory-Methods

ProductsProducts

Factory Method Vs. Abstract FactoryThe difference is merely in the order of sets

Isomorphisms are preserved

Page 30: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

30

Two-Tier Programming

Integrating Intentional With Extensional programming

Page 31: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

31

Multiple Representations

TextViews

observer

observableI

ScrollViews

Update(Observable)

addObserver(Observer)

notifyObservers

C'tormodel

AccessorsMutators

update(Observable)

Update(Observable)

C'tor

subject

observers

update(subject)

attach(observers)

detach(observers)

notify

concrete-subject

Set-state

get-State

public class Observable { public synchronized void addObserver(Observer o) { ... } public void notifyObservers(Object arg) { ... }}

public class Observable { public synchronized void addObserver(Observer o) { ... } public void notifyObservers(Object arg) { ... }}

class MyObservable extends Observable {public void access() { ... }public void mutate() { ... notifyObservers(); }}

class MyObservable extends Observable {public void access() { ... }public void mutate() { ... notifyObservers(); }}

intrface Observer { void update(Observable); }

intrface Observer { void update(Observable); }

class ScrollView extends Scrollbar implements Observer { … }

class ScrollView extends Scrollbar implements Observer { … }

class TextView extends TextField implements Observer {public TextView(Counter c) { ... }public void update(Observable o, Object counter) { ... }}

class TextView extends TextField implements Observer {public TextView(Counter c) { ... }public void update(Observable o, Object counter) { ... }}

Source Code

Pattern

Design Model

observable

observers

update(observable)

attach(observers)

notify

model

Mutators

Accessors

Instance of a pattern

Extensional tier

Intentional tier

Page 32: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

32

subject

observers

update(subject)

attach(observers)

detach(observers)

notify

concrete-subject

Set-state

get-State

Coordination

TextViews

observer

observableI

ScrollViews

Update(Observable)

addObserver(Observer)

notifyObservers

C'tormodel

AccessorsMutators

update(Observable)

Update(Observable)

C'tor

public class Observable { public synchronized void addObserver(Observer o) { ... } public void notifyObservers(Object arg) { ... }}

public class Observable { public synchronized void addObserver(Observer o) { ... } public void notifyObservers(Object arg) { ... }}

class MyObservable extends Observable {public void access() { ... }public void mutate() { ... notifyObservers(); }}

class MyObservable extends Observable {public void access() { ... }public void mutate() { ... notifyObservers(); }}

intrface Observer { void update(Observable); }

intrface Observer { void update(Observable); }

class ScrollView extends Scrollbar implements Observer { … }

class ScrollView extends Scrollbar implements Observer { … }

class TextView extends TextField implements Observer {public TextView(Counter c) { ... }public void update(Observable o, Object counter) { ... }}

class TextView extends TextField implements Observer {public TextView(Counter c) { ... }public void update(Observable o, Object counter) { ... }}

Source Code

Pattern

Design Model

observable

observers

update(observable)

attach(observers)

notify

model

Mutators

Accessors

Instance of a pattern

Coordination

Page 33: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

33

Coordination: Part I

TextViews

observer

observableI

ScrollViews

Update(Observable)

addObserver(Observer)

notifyObservers

C'tormodel

AccessorsMutators

update(Observable)

Update(Observable)

C'tor

public class Observable { public synchronized void addObserver(Observer o) { ... } public void notifyObservers(Object arg) { ... }}

public class Observable { public synchronized void addObserver(Observer o) { ... } public void notifyObservers(Object arg) { ... }}

class MyObservable extends Observable {public void access() { ... }public void mutate() { ... notifyObservers(); }}

class MyObservable extends Observable {public void access() { ... }public void mutate() { ... notifyObservers(); }}

intrface Observer { void update(Observable); }

intrface Observer { void update(Observable); }

class ScrollView extends Scrollbar implements Observer { … }

class ScrollView extends Scrollbar implements Observer { … }

class TextView extends TextField implements Observer {public TextView(Counter c) { ... }public void update(Observable o, Object counter) { ... }}

class TextView extends TextField implements Observer {public TextView(Counter c) { ... }public void update(Observable o, Object counter) { ... }}

Source Code

Design Model

Parsing/Reverse engineering

Page 34: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

34

Coordination: Part II

TextViews

observer

observableI

ScrollViews

Update(Observable)

addObserver(Observer)

notifyObservers

C'tormodel

AccessorsMutators

update(Observable)

Update(Observable)

C'tor

Design Model

observable

observers

update(observable)

attach(observers)

notify

model

Mutators

Accessors

Instance of a pattern

<observers, observer, TextView, ScrollView>

<observers.update,observer.update, TextView.update,

ScrollView.update>

Page 35: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

35

subject

observers

update(subject)

attach(observers)

detach(observers)

notify

concrete-subject

Set-state

get-State

Coordination: Part III

observable

observers

update(observable)

attach(observers)

notify

model

Mutators

Accessors

Pattern

Instance of a pattern

<Observers, Observers><subject, observable><concrete-subject, model><Set-state, Mutators><Observers.update,

Observers.update>…

Page 36: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

36

Tool Support The Software Architecture Lab, Concordia U. Architectural Reflection projects:

Visualization tool Specifications with a graphic editor

Parser for symbolic specifications Reverse engineering from Java

In collaboration with IBM Research Centre, Haifa

pattern AbstractFactory is FactoryMethods in P2(F), Creators in H, Products in P(H) where tribe (FactoryMethods, Creators), production <-> (FactoryMethods, Products), return_type <-> (FactoryMethods, Products).

pattern AbstractFactory is FactoryMethods in P2(F), Creators in H, Products in P(H) where tribe (FactoryMethods, Creators), production <-> (FactoryMethods, Products), return_type <-> (FactoryMethods, Products).

Page 37: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

37

Implementation in Prolog LePUS is readily implemented in PROLOG:

Supported activities: Validation Application Recognition Discovery

FactoryMethod(hierarchy_structure (Creators_root, Creators_Leaves), hierarchy_structure (Products_root, Products_Leaves), FactoryMethods) :- clan(FactoryMethods,[Creators_root|Creators_Leaves]), isomorphic(production, FactoryMethods, [Products_root|Products_Leaves]).

FactoryMethod(hierarchy_structure (Creators_root, Creators_Leaves), hierarchy_structure (Products_root, Products_Leaves), FactoryMethods) :- clan(FactoryMethods,[Creators_root|Creators_Leaves]), isomorphic(production, FactoryMethods, [Products_root|Products_Leaves]).

Page 38: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

38

Limitations “Design Models”: Static properties

Cannot give behavioural specifications

Relations are abstract Cannot represent more than

one relationships between (Journey, Location)

Journey Location

origin

destination

Page 39: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

39

Future Directions Sample specifications

Common libraries & Frameworks

Behavioural specifications Use Gurevich’s Abstract State Machines (“evolving

algebras”)

Tool support Forward and reverse engineering

Formalization of the visual language Design visual primitives & operators Visual semantics & syntax

Page 40: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

40

ReferencesD. E. Perry, A. L. Wolf (1992). "Foundation for the Study of

Software Architecture." ACM SIGSOFT Software Engineering Notes Vol. 17, No. 4.

M. Shaw, D. Garlan (1996). Software Architecture: Perspectives on an Emerging Discipline. Prentice Hall.

E. Gamma, R. Helm, R. Johnson, J. Vlissides (1994). Design Patterns: Elements of Reusable Object Oriented Software. Addison-Wesley

Page 41: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

41

BibliographyFull text: http://www.eden-study.org/

Ontology : A. H. Eden Y. Hirshfeld, "Principles in Formal Specification of Object Oriented Architectures.“CASCON 2001, November 5-8, 2001, Toronto, Canada.

LePUS: A. H. Eden (2001). "Formal Specification of Object-Oriented Design." International Conference on Multidisciplinary Design in Engineering CSME-MDE 2001, November 21-22, 2001, Montreal, Canada.

Visual Notation: A. H. Eden (2002). “Design Schemata.” Submitted: Annals of Software Engineering, Special Volume on Software Visualization.

Page 42: 1 Formal Specification of Object-Oriented Design Amnon H. Eden Department of Computer Science, University of Essex Research seminar given at the Department

42

Bibliography (Cont.)The Patterns’ Wizard. A. H. Eden, J. Gil, A. Yehudai (1997).

"Precise Specification and Automatic Application of Design Patterns." Proceedings of the Twelve IEEE International Automated Software Engineering Conference (ASE 1997), Lake Tahoe, Nevada Los Alamos, IEEE Computer Society Press, Nov. 3-5, 1997.

Two-Tier Programming. A. H. Eden, J. Jahnke (2002) "Coordinating Software Evolution Via Two-Tier Programming," Coordination 2002, Lecture Notes in Computer Science 2315, pp. 149-159. Berlin: Springer-Verlag.

Intention/Locality. A. H. Eden (2002). “Architecture, Design, Implementation.” Submitted: Journal of Software and System Modeling (SoSyM). Berlin: Springer.