Read fwkswkshop.pdf text version

Using model frameworks

Alan Cameron Wills Building models from TriReme International Ltd

Generic Frameworks

(C) Copyright 1997 Trireme International Ltd

Alan Cameron Wills

Building Models from Generic Frameworks

Alan Cameron Wills Trireme International Ltd

http://www.trireme.com [email protected] 0161 225 3240

(C) Copyright 1997 Trireme International Ltd

Reuse is why we like Objects

s

"What is your principal motivation for taking up object technology?"

q Fast

development? Fast develop Quality q Better quality? Reuse q Reuse? [Unix News May 95 p48] 0

s

10

20

30

40

So are you getting it ...?

(C) Copyright 1997 Trireme International Ltd

Reuse is ...

s

Cutting and pasting ("cloning")?

adopt, adapt, & improve

older applic

newer applic

OK at first, but no help with change

s

Imported components

include unaltered

applications

Library of generic components

(C) Copyright 1997 Trireme International Ltd

Better at dealing with change -- though components in Library must be generalised

So what's in the Library?

s

Generic components:

q Classes;

Class templates q Collaboration frameworks any chunk q Specifications of work q Patterns q Application frameworks q Operating Systems, Databases, GUIs q Standards q Plans q General advice

(C) Copyright 1997 Trireme International Ltd

Library asset = any generic chunk of work

Any chunk of work that can be generalised and combined with other such chunks s In OOD, the focus of design work is on collaborations and responsibilities:

s

q As

library assets, collaborations are at least as useful as classes

(C) Copyright 1997 Trireme International Ltd

Collaborations as reusable chunks

Collab 1 Collab 2

role B

e.g. ModelViewController

role A

refines

Collab 12

e.g. Façade & subsystemobjects

e.g. View & Controller of a Façade of a subsystem

(C) Copyright 1997 Trireme International Ltd

role A

role B

Aim: tool for building designs from generic frameworks

s

Designs -- not necessarily code

1 specification of how to fulfill

its role in Collab 1

design of how Collab 2 fulfills its goal with participants as specified

2.2

2.1

specification of how to fulfill its role in Collab 2

3 AND

specification of how to fulfill its roles in both Collab 1 and Collab 2

(C) Copyright 1997 Trireme International Ltd

4 your implementation

Framework application

Observation Subject [value\calls.length] CallQueue

calls [ ] source waitAlarm add (call) call get() ...

Observer [value\reading] Thermometer

reading max, min colour display ( ) ...

(C) Copyright 1997 Trireme International Ltd

Agenda

s

Drawing & composing generic partial models

­ Static models -- no interactions

q Relation

to subtypes

s s

Specifying collaborations

­ Interactions happening

Composing collaborations s Conclusions, if any s Thanks to John Cameron / OT96

(C) Copyright 1997 Trireme International Ltd

Generalisation

s

?

Car speed direction max speed start stop turn shift(gear)

(C) Copyright 1997 Trireme International Ltd

attributes

operations

Ship speed direction stability start stop turn splice(brace) ?

Generalisation

Vehicle speed direction start stop turn

Car max speed shift(gear)

Ship stability splice(brace)

(C) Copyright 1997 Trireme International Ltd

Into the problem: 1. A small model.

A car hire company rents cars for individual days. Cars must not be double-booked, and the car allocated to a specific hire must meet the requirements of the customer. Requirements are chosen from a set including things like `4 door', `big boot', `drinks cabinet', `auto-shift', etc. s Never mind the operations for now; just draw a type diagram and invariants.

s

(C) Copyright 1997 Trireme International Ltd

?

Day Hire Cars Car registration car 1 *

My solution

* schedule Hire * date

features * requirement Car Feature *

-- No Car is double booked -Car :: forall h1, h2 in schedule, h1 != h2 => h1.date != h2.date -- requirements of every Hire are met -Hire :: requirement subsetOf car.features

· Precise notation complements and disambiguates

(C) Copyright 1997 Trireme International Ltd

2. Another model

q The

Levenshulme Whistle has a fixed layout. Reporters are required every week to fill each slot with a story. Each slot has a fixed set of characteristics to which the story in it must conform:

Rescued cat

local; mugg-foreign; ing disaster female clergy; sex celeb ; charity; local local; car crash youth; charity local; conviction

Levenshulme Whistle

photo

national; politician; scandal

hospital; scandal

Local; sex; politician page 3

etc.

page 1

page 2

page 4

(C) Copyright 1997 Trireme International Ltd

Levenshulme Whistle Slot position slot 1 *

* schedule Story * text date

0,1

character *

requirement * Story Characteristic

-- Each Slot has one Story on a given Date -Slot :: forall story1, story2 in schedule, story1 != story2 => story1.date != story2.date -- requirements of every Slot are met -Slot :: requirement subsetOf slot.character

Photo

(C) Copyright 1997 Trireme International Ltd

· Generalise ; apply to each case ...

?

A Generalisation (?)

Resource Allocation Resource slot 1 *

* schedule Usage * date

features * requirement Feature *

-- Each Resource has one Usage on a given Date -Resource :: forall r1, r2 in schedule, r1 != r2 => r1.date != r2.date

(C) Copyright 1997 Trireme International Ltd

· Apply to each case... ?

The Wrong Specialisation ?

Resource Allocation

· 2 problems ?

subtype of

Day Hire Cars Car registration

Resource slot 1 * schedule Usage * date

*

Levenshulme Whistle

* * Feature

Slot

-- Each Resource has one Usage on a given Date -Resource :: forall r1, r2 in schedule, r1 r2 => r1.date r2.date

Hire

imports

Car Feature

(C) Copyright 1997 Trireme International Ltd

Story text

1

Story Characteristic

*

Photo

Subtyping inappropriate

Can you Hire a Slot? Can you assign a Car to a Story? Can a Car have Sex, or a Story have luggage space? s We talk about the features of a Car, but the character of a Story. The relationships are homomorphic, but differently-named.

s

(C) Copyright 1997 Trireme International Ltd

Substitution the solution

Resource Allocation Resource slot 1 * schedule Usage * date

macro import with renaming

[Resource\Car, Usage\ Hire, Feature \ CarFeature]

*

*

* Feature

Day Hire Car Car slot 1 * schedule Hire * date *

-- Each Resource has one Usage on a given Date -Resource :: forall r1, r2 in schedule, r1 r2 => r1.date r2.date

*

* CarFeature

-- Each Car has one Hire on a given Date -Car :: forall r1, r2 in schedule, r1 r2 => r1.date r2.date

(C) Copyright 1997 Trireme International Ltd

DayHireCar = ResourceAllocation [ Resource \ Car, Usage \ Hire, Feature \ CarFeature ] Levenshulme Whistle = ResourceAllocation [ Resource \ Slot, Usage \ Story,

Macro import

text version

DayHireCar = ( ResourceAllocation [ Resource \ Car, Usage \ Hire, Feature \ CarFeature ] && Hire:: car.features subsetOf features ) Levenshulme Whistle = ( ResourceAllocation [ Resource \ Slot, Usage \ Story, Feature \ StoryChrtrstic] && Story:: features subsetOf slot.features )

(C) Copyright 1997 Trireme International Ltd

pictorial version

Levenshulme Whistle

imported package

Resource Allocation Resource Usage Story text Slot position

1

Feature StoryChtrstic

Photo

*

· Most useful if there is a tool for it · You supply this info; tool unfolds to complete defns

Nearest tools to date

s

Some tools (such as Rose) have a facility for applying a script to a model

q This

is not an import

­ subsequent alterations to generic part have no opportunity to propagate

q There

is no way of making a generic model

­ you have to write a script s

They can't compose the operation frameworks that we'll look at shortly

(C) Copyright 1997 Trireme International Ltd

More

Ensure theWhistle's staff aren't overworked: each Reporter should only handle one story in each issue. s Each Reporter is able to handle Stories with certain Characteristics. We need to ensure the Reporter assigned to every Story has the skills for the job. s What's the easy way to add these to our model?

s

(C) Copyright 1997 Trireme International Ltd

Multiple macro application

Levenshulme Whistle Resource Allocation Feature Usage Resource

Resource Allocation

Feature Usage

StoryChtrstic Story date Reporter

Slot

1

*

Photo

Resource [features\skills]

Is this useful? s Does it make anything easier? s Are there tools that do this?

s Result ->

(C) Copyright 1997 Trireme International Ltd

Levenshulme Whistle Slot position

1

*

1

Reporter name

*

* Story text date

0,1

schedule

* * *

skills * * Story Characteristic

-- Each Slot has one Story on a given Date -Slot :: forall story1, story2 in schedule, story1 != story2 => story1.date != story2.date -- requirements of every Story are met -Story :: requirement subsetOf slot.character -- Each Reporter has one Story on a given Date -Reporter :: forall story1, story2 in schedule, story1 != story2 => story1.date != story2.date -- requirements of every Story are met -Story :: requirement subsetOf reporter.skills

*

Photo

(C) Copyright 1997 Trireme International Ltd

Modelling conundrum

Animals eat Food s Cows is Animals s Burgers is Food s => Cows eat Burgers s? s Sort out the mistake. s Model this correctly

s

(C) Copyright 1997 Trireme International Ltd

?

Species -- Food relation

s

Every Species of Animal has a Food it eats; Cows is a Species; Grass is a Food

Food diet FoodType * CowGust Gustation

s Gustation Animal Species

*

Species

FoodType

Cows

Grass

(C) Copyright 1997 Trireme International Ltd

Operations

s

Pre/postconditions

q Postconditions

specify what's required, but can leave some aspects open to implementor or further specification (in specialisations)

Circle float radius Point centre alignWith(Circle c2) post centre==c2.centre ...

(C) Copyright 1997 Trireme International Ltd

Collaborations & responsibilities

s

Key OO design decision: who does what

­ distribution of responsibilities between collaborators

qA

good design notation should allow documentation of the state of the design both before and after each such decision is made

s

"Collaboration": interative relationship

(C) Copyright 1997 Trireme International Ltd

Collaborations

Sales Before taking decisions about who initiates actions: Owner Buyer pocket

1

stock Thing * price Vendor till

pay supply

(C) Copyright 1997 Trireme International Ltd

action pay (buyer, vendor, amount) pre buyer.pocket > amount post buyer.pocket ­= amount && vendor.till += amount action supply (vendor, buyer, thing) pre vendor.stock includes thing post vendor.stock ­= thing && buyer.stock += thing

Refining and abstracting collaborations

s

Pay and supply are abstractions.

q What

could replace them in a more refined design, one step closer to the code? q What could they be refinements of? What would its pre/post spec look like?

­ How are they related to it? s

How would this model apply to:

q Aperson

and a drinks vending machine? q A retailer and a distributor? -- AND: q A retailer and a customer?

(C) Copyright 1997 Trireme International Ltd

Abstract action

Sales Spec

pay(buyer, vendor, thing) && supply (vendor, buyer, thing) => sale (thing, buyer, vendor)

Owner Buyer pocket

1

stock Thing * price Vendor till

sale

Sales

action sale (thing, buyer, vendor) pre buyer.pocket > thing.price post buyer.pocket ­= thing.price && vendor.till += thing.price && buyer.stock += thing && vendor.stock ­= thing

(C) Copyright 1997 Trireme International Ltd

DrinksVendingModel Sales

Buyer

Generic Model Instantiation

Vendor [till\cashbox]

Customer

Drinks Machine SaleChain Sales

Buyer Vendor

Sales

Buyer [pocket\till] Vendor

Customer

(C) Copyright 1997 Trireme International Ltd

Retailer

Wholesaler

Unfolded composite

SalesChain Owner Customer pocket pay supply Retailer till

1

·Tool could show this on request

stock

Thing * price

pay supply

Wholesaler till

action pay (customer, retailer, amount) pre customer.pocket> amount post customer.pocket ­= amount && retailer.till += amount action supply (retailer, customer, thing) pre retailer.stock includes thing post retailer.stock ­= thing && customer.stock += thing

(C) Copyright 1997 Trireme International Ltd

action pay (retailer, wholesaler, amount) pre retailer.till> amount post retailer.till ­= amount && wholesaler.till += amount action supply (wholesaler, retailer, thing) pre wholesaler.stock includes thing post wholesaler.stock ­= thing && retailer.stock += thing

Decoupling generic models

s

What prompts buying in:

qa

Retailer or Distributor? q a Restaurant or Factory?

What's common between these? s Separation of concerns: in what generic model should we record what prompts buying?

s

q Model

describing buying new stock? q Model describing consumption of stock?

(C) Copyright 1997 Trireme International Ltd

`Abstract hook' actions

Sales Owner

1

stock Thing * price

Buyer Vendor sale Any other action pocket till that causes threshold the buyer's stock to drop below a post buyer.stock < buyer.threshold ==> threshold action sale (buyer, vendor, amount) results in a sale pre ...// can only happen if this true post ...

(C) Copyright 1997 Trireme International Ltd

Model framework composition

s

What causes the Retailer to buy new stock from the Wholesaler?

Sales

Buyer Vendor

Sales

Buyer [pocket\till] Vendor

Customer s

Retailer

Wholesaler

Depletion of stock

(C) Copyright 1997 Trireme International Ltd

Using generic models

s

Model frameworks give specifications for classes that play multiple roles s With clever architecture, you can either

q build

corresponding implementations that plug together in many combinations; q or use the generic models to do the design, and complete it by coding the classes from the resulting specs.

(C) Copyright 1997 Trireme International Ltd

Roles composition & subtyping

(C) Copyright 1997 Trireme International Ltd

Conclusions

As reusable assets, generic model frameworks are as good as classes s Roles are not substituble subtypes s Model frameworks are the formalisable part of design patterns

s

(C) Copyright 1997 Trireme International Ltd

Information

40 pages

Report File (DMCA)

Our content is added by our users. We aim to remove reported files within 1 working day. Please use this link to notify us:

Report this file as copyright or inappropriate

763237


Notice: fwrite(): send of 207 bytes failed with errno=104 Connection reset by peer in /home/readbag.com/web/sphinxapi.php on line 531