lecture 5 part 1 - york university

23
Lecture 5 Part 1 Expanded Types for Compositions

Upload: others

Post on 15-Mar-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Lecture 5

Part 1

Expanded Types for Compositions

Modelling: Aggregation vs. Composition

f - - -

in:*:c. GE(prepositions

)

× →shared Astarte(aggregations

Expanded Type for Composition

⇒( x -1¥:*:÷i÷L a÷:*:↳

÷::*:÷::c::..i¥¥¥.org

,

part .

Use of Expanded Type\

f¥bYE"gegfdre.es

÷¥¥÷¥":"⇐T

V

- - - -

v⇒. -

→}⇒e TOHis u vdoesnotapy address to-t④EI4*.IE#sin9fYITYy.ovgkaFItents .

EXERCISE

mmmm

Reference Type or Expanded Type-

i chaffed, AUTHOR µdaue¥¥AoTHoRad :

700uhaggregation das;sB0¥¥ sharing )(sharing) author :

qd expanded AUTHOR

Lecture 5

Part 2

Sharing via Inheritance

Shared Data via Inheritance CohesionSingle Choice Principle#

→⑨⑤ ped

A class has a unifying theme ofpurpose (a1 features are

relevant w- r-t . that

inherited-6 purposes.DEPOSIT

Shared Data via Inheritance

d1, d2: DEPOSITw1, w2: WITHDRAWt1, t2: INTERNATIONAL_TRANSFER...d1.set_max_balancew2.set_min_balancet2.set_exchange_rate

irerminmax

DEPOSIT0.112.3410001000000

irerminmax

DEPOSIT0.112.3410001000000

irerminmax

WITHDRAW0.112.3410001000000

irerminmax

WITHDRAW0.112.3410001000000

irerminmax

TRANSFER0.112.3410001000000

irerminmax

TRANSFER0.112.3410001000000

CohesionSingle Choice Principle--

÷ .÷÷¥¥⇐÷÷÷÷÷÷÷: i.

Lecture 5

Part 3

Once Routines

Once Routine (1)

÷:÷÷.--

→I- - E--

→ 1stcall

=-

Dg- -¥÷¥i

Once Routine (2)¥2 s "Mark's

→s- -

11K¥ .o

. -o

( subset. Once Routine

sina.fi:S:c .".in.- -

r

Approximating Once Routines in Java (1)

ftp.harngis not guaranteed.

I

'' i÷i÷÷

Approximating Once Routines in Java (2)

on.

Lecture 5

Part 4

Export Status

Export Status Case 1

class SUPPLIER

create make

feature make (init_i: INTEGER) do i := init_i end

feature i: INTEGERend

class CLIENT_1 ... test: BOOLEAN local s, old_s: SUPPLIER do create s.make (5) old_s := s create s.make (5) print (old_s = s) old_s := s s.make (7) print (old_s = s) endend

class CLIENT_2 ... test: BOOLEAN local s, old_s: SUPPLIER do create s.make (5) old_s := s create s.make (5) print (old_s = s) old_s := s s.make (7) print (old_s = s) endend

i -15:¥¥i¥¥ ' =÷÷:÷:...""s E¥÷÷÷÷:.0¥ . .

Export Status Case 2

class SUPPLIER

create make

feature make (init_i: INTEGER) do i := init_i end

feature i: INTEGERend

class CLIENT_1 ... test: BOOLEAN local s, old_s: SUPPLIER do create s.make (5) old_s := s create s.make (5) print (old_s = s) old_s := s s.make (7) print (old_s = s) endend

class CLIENT_2 ... test: BOOLEAN local s, old_s: SUPPLIER do create s.make (5) old_s := s create s.make (5) print (old_s = s) old_s := s s.make (7) print (old_s = s) endend

Export Status Case 3

class SUPPLIER

create make

feature make (init_i: INTEGER) do i := init_i end

feature i: INTEGERend

class CLIENT_1 ... test: BOOLEAN local s, old_s: SUPPLIER do create s.make (5) old_s := s create s.make (5) print (old_s = s) old_s := s s.make (7) print (old_s = s) endend

class CLIENT_2 ... test: BOOLEAN local s, old_s: SUPPLIER do create s.make (5) old_s := s create s.make (5) print (old_s = s) old_s := s s.make (7) print (old_s = s) endend

Lecture 5

Part 5

Singleton Pattern

Singleton Design Pattern: Code (1)-

di#t

going. as.aons-m.dz#t

- o. *

-0 aeEATBmdae .E'Ian¥¥i÷÷÷÷÷÷⇒÷.

IT#diii.ie

Singleton Design Pattern: Code (2.1)#

Singleton Design Pattern: Code (2.2)

client_1

DATA+

create{DATA_ACCESS}--CreationRestrictionmake

feature{DATA_ACCESS}--UpdateRestrictionmake+--Initializeadataobject

feature--Datav:SOME_DATA_CLASS

--Anexamplequeryc--Anexamplecommand

DATA_ACCESS+

feature--Datadata+:DATA--ReferencetoashareddataobjectoncecreateResult.makeend

invariantshared_instance:data=data

data+

supplier_of_shared_data

data_access+

+

APPLICATION_1

client_2

+

APPLICATION_2

client_3

+

APPLICATION_3

data_access+

data_access+

•data-a:TAAefIdFndI .

AO-

I← 0I

.

& ref . eq .→

O.