05DomainModel UML

34
OO domain modeling OO domain modeling with UML class diagrams with UML class diagrams and CRC cards and CRC cards CSE432 CSE432 Prof Glenn Blan Prof Glenn Blan

Transcript of 05DomainModel UML

Page 1: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 1/34

OO domain modelingOO domain modeling

with UML class diagramswith UML class diagrams

and CRC cardsand CRC cards

CSE432CSE432

Prof Glenn BlanProf Glenn Blan

Page 2: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 2/34

!hat is a "omain Model#!hat is a "omain Model#

$ll%strates meaningf%l conce&t%al classes$ll%strates meaningf%l conce&t%al classes

in &ro'lem domainin &ro'lem domain

Re&resents real(world conce&ts)Re&resents real(world conce&ts)not software com&onentsnot software com&onents

Software(oriented class diagrams willSoftware(oriented class diagrams will

'e de*elo&ed later) d%ring design'e de*elo&ed later) d%ring design

Page 3: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 3/34

 + "omain Model is Conce&t%al) + "omain Model is Conce&t%al)

not a Software +rtifactnot a Software +rtifact

SaleSale

amtamt

itemitem

Sales"ata'aseSales"ata'ase

SaleSale

"o%'le amt,"o%'le amt,$tem item,$tem item,

*oid &rint-.*oid &rint-.

Conce&t%al Class/Conce&t%al Class/ Software +rtifacts/

*s0

!hat1s the!hat1s the

difference#difference#

Page 4: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 4/34

"omain Model Relationshi&s"omain Model Relationshi&s

Domain Model

Use Case Model

Interaction Diagrams

Glossary

Dynamic Behavior 

Functional Requirements

Conceptual Class

DiagramClasses, attributes, associations

Domain

obects

De!ine terms

"hat do you learn about #hen and ho# to create these models$

Page 5: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 5/34

$dentif conce&t%al classes$dentif conce&t%al classes

from no%n &hrasesfrom no%n &hrases

ision and Sco&e) Glossar and Use Casesision and Sco&e) Glossar and Use Cases

are good for this t&e of ling%istic analsisare good for this t&e of ling%istic analsis

owe*er/owe*er/

!ords ma 'e am'ig%o%s or snonmo%s!ords ma 'e am'ig%o%s or snonmo%s5o%n &hrases ma also 'e attri'%tes or5o%n &hrases ma also 'e attri'%tes or&arameters rather than classes/&arameters rather than classes/ $f it stores state information or it has m%lti&le$f it stores state information or it has m%lti&le

'eha*iors) then it1s a class'eha*iors) then it1s a class $f it1s 6%st a n%m'er or a string) then it1s &ro'a'l$f it1s 6%st a n%m'er or a string) then it1s &ro'a'l

an attri'%tean attri'%te

Page 6: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 6/34

7rom 5Ps to classes or attri'%tes7rom 5Ps to classes or attri'%tes

8he +8M *erifies whether the c%stomer9s card n%m'er and P$5 are correct0S O O O$f it is) then the c%stomer can chec the acco%nt 'alance) de&osit cash) and withdraw cash0

S O O O

Checing the 'alance sim&l dis&las the acco%nt 'alance0

S O O

"e&ositing ass the c%stomer to enter the amo%nt) then %&dates the acco%nt 'alance0

S O O O!ithdraw cash ass the c%stomer for the amo%nt to withdraw, if the acco%nt has eno%gh cash)

  S O O O S O

the acco%nt 'alance is %&dated0 8he +8M &rints the c%stomer1s acco%nt 'alance on a recei&t0

  O S O O

 +nal:e each subject and object as follows/"oes it re&resent a &erson &erforming an action# 8hen it1s an actor) ;R10

$s it also a *er' -s%ch as ;de&osit1.# 8hen it ma 'e a method) ;M10

$s it a sim&le *al%e) s%ch as ;color1 -string. or ;mone1 -n%m'er.#

8hen it is &ro'a'l an attri'%te) ;A10

!hich 5Ps are %nmared# Mae it ;C1 for class0

er's can also 'e classes) for e<am&le/"e&osit is a class if it retains state information

R

R

M

M

A   A

A

A

A   A

A

A A

A   A

A A

A

C

C

R

M

R

Consider the following &ro'lem descri&tion) anal:ed for S%'6ects) er's) O'6ects/

C

Page 7: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 7/34

Ste&s to create aSte&s to create a

"omain Model"omain Model

$dentif candidate conce&t%al classes$dentif candidate conce&t%al classes

"raw them in a UML domain model"raw them in a UML domain model

 +dd associations necessar to record +dd associations necessar to record

the relationshi&s that m%st 'e retainedthe relationshi&s that m%st 'e retained

 +dd attri'%tes necessar for information +dd attri'%tes necessar for information

to 'e &reser*edto 'e &reser*ed

Use e<isting names for things)Use e<isting names for things)

the *oca'%lar of the domainthe *oca'%lar of the domain

Page 8: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 8/34

==

Mono&ol Game domain modelMono&ol Game domain model

-first identif conce&ts as classes.-first identif conce&ts as classes.

Mono&ol Game

Plaer  Piece

"ie Board

S>%are

Page 9: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 9/34

Mono&ol Game domain modelMono&ol Game domain model

Larman) 7ig%re ?02=Larman) 7ig%re ?02=

Page 10: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 10/34

"isco*ering the "omain Model with CRC cards"isco*ering the "omain Model with CRC cards(See multimedia from(See multimedia from The Universal MachineThe Universal Machine on CRC cards:on CRC cards:

umwordsumwords))

"e*elo&ed ' Bec and C%nningham at 8etroni<"e*elo&ed ' Bec and C%nningham at 8etroni< See htt&/@@c20com@doc@oo&sla=?@&a&er0htmlSee htt&/@@c20com@doc@oo&sla=?@&a&er0html

8his is the same Aent Bec that later wrote the 'oo8his is the same Aent Bec that later wrote the 'oo

&ioneering E<treme Programming -P.&ioneering E<treme Programming -P.

CRC cards are now &art ofCRC cards are now &art of XPXP

Page 11: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 11/34

Low(techLow(tech

Ordinar inde< cardsOrdinar inde< cards Each card re&resents aEach card re&resents a classclass of o'6ects0of o'6ects0

3< is &refera'le to 4<D at least earl on !h#3< is &refera'le to 4<D at least earl on !h#

Each card has three com&onentsEach card has three com&onents 5ame) Res&onsi'ilities) Colla'orators5ame) Res&onsi'ilities) Colla'orators

Page 12: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 12/34

Res&onsi'ilitiesRes&onsi'ilities

Ae idea/ o'6ects ha*eAe idea/ o'6ects ha*e res&onsi'ilitiesres&onsi'ilities  +s if the were sim&le agents -or actors in scenarios. +s if the were sim&le agents -or actors in scenarios.

 +nthro&omor&hism +nthro&omor&hism of class res&onsi'ilities getsof class res&onsi'ilities getsawa from thining a'o%t classes as 6%st dataawa from thining a'o%t classes as 6%st data

holdersholders FFO'6ect thin foc%ses on their acti*e 'eha*iorsO'6ect thin foc%ses on their acti*e 'eha*iors

Each o'6ect is res&onsi'le for s&ecific actionsEach o'6ect is res&onsi'le for s&ecific actions Client can e<&ect &redicta'le 'eha*iorsClient can e<&ect &redicta'le 'eha*iors

Res&onsi'ilit also im&lies inde&endence/Res&onsi'ilit also im&lies inde&endence/ 8o tr%st an o'6ect to 'eha*e as e<&ected is to rel %&on8o tr%st an o'6ect to 'eha*e as e<&ected is to rel %&on

its a%tonom and mod%laritits a%tonom and mod%larit arder to tr%st o'6ects easil ca%ght %& in de&endenciesarder to tr%st o'6ects easil ca%ght %& in de&endencies

ca%sed ' glo'al *aria'les and side effects0ca%sed ' glo'al *aria'les and side effects0

Page 13: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 13/34

Class namesClass names

Class NameClass Name creates the *oca'%lar of o%r analsiscreates the *oca'%lar of o%r analsis Use no%ns as class names) thin of them as sim&le agentsUse no%ns as class names) thin of them as sim&le agents er's can also 'e made into no%ns) if the are maintain stateer's can also 'e made into no%ns) if the are maintain state E0g0) Freads card s%ggestsE0g0) Freads card s%ggests CardReader CardReader ) managing 'an cards) managing 'an cards

Use &rono%ncea'le names/Use &rono%ncea'le names/

$f o% cannot read alo%d) it is not a good name$f o% cannot read alo%d) it is not a good nameUse ca&itali:ation to initiali:e Class names andUse ca&itali:ation to initiali:e Class names and

demarcate m%lti(word namesdemarcate m%lti(word names E0g0) CardReader rather than C+R"RE+"ER or cardHreaderE0g0) CardReader rather than C+R"RE+"ER or cardHreader !h do most OO de*elo&ers &refer this con*ention#!h do most OO de*elo&ers &refer this con*ention#

 +*oid o'sc%re) am'ig%o%s a''re*iations +*oid o'sc%re) am'ig%o%s a''re*iations E0g0) is 8ermProcess something that terminatesE0g0) is 8ermProcess something that terminates

or something that r%ns on a terminal#or something that r%ns on a terminal#

8r8r not not  to %se digits within a name) s%ch as CardReader2to %se digits within a name) s%ch as CardReader2 Better for instances than classes of o'6ectsBetter for instances than classes of o'6ects

Page 14: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 14/34

ResponsibilitiesResponsibilities sectionsection

"escri'es a class1s"escri'es a class1s behaviorsbehaviors "escri'e"escri'e what what  is to 'e done) notis to 'e done) not how how II

Use short *er' &hrasesUse short *er' &hrases E0g0/ Freads card or Floo %& wordsE0g0/ Freads card or Floo %& words

ow do constraints of inde< cards g%ide classow do constraints of inde< cards g%ide class

analsis#analsis#

 + good meas%re of a&&ro&riate com&le<it + good meas%re of a&&ro&riate com&le<it $f o% cannot fit eno%gh tass on a card)$f o% cannot fit eno%gh tass on a card)

ma'e o% need to di*ide tass 'etween classes)ma'e o% need to di*ide tass 'etween classes)

on different cards#on different cards#

Page 15: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 15/34

Colla'oratorsColla'orators

Lists im&ortantLists im&ortant supplierssuppliers and &ossi'l clients of a classand &ossi'l clients of a class

!h are classes that s%&&l ser*ices more im&ortant here#!h are classes that s%&&l ser*ices more im&ortant here# S%&&liers are necessar for the descri&tion of res&onsi'ilitiesS%&&liers are necessar for the descri&tion of res&onsi'ilities

 +s o% write down res&onsi'ilities for a class) add an +s o% write down res&onsi'ilities for a class) add ans%&&liers needed for thems%&&liers needed for them 7or e<am&le Fread dictionar o'*io%sl im&lies that7or e<am&le Fread dictionar o'*io%sl im&lies that

a Fdictionar as a colla'orator a Fdictionar as a colla'orator 

"e*elo&ing CRC cards is first a &rocess of disco*ering"e*elo&ing CRC cards is first a &rocess of disco*ering

classes and their res&onsi'ilitiesclasses and their res&onsi'ilities Peo&le nat%rall &ercei*e the world as categories of o'6ectsPeo&le nat%rall &ercei*e the world as categories of o'6ects $n o'6ect(oriented analsis) one disco*ers new categories$n o'6ect(oriented analsis) one disco*ers new categories

rele*ant to a &ro'lem domainrele*ant to a &ro'lem domain

Page 16: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 16/34

CRC card sim%lationsCRC card sim%lations

"esigning for res&onsi'ilit in*ol*es"esigning for res&onsi'ilit in*ol*es simulationsimulation O'6ects model a world interacting 'eha*iorsO'6ects model a world interacting 'eha*iors  +fter de*elo&ing a set of CRC cards) r%n +fter de*elo&ing a set of CRC cards) r%n simulationssimulations  AKA AKA structured al!throu"h scenariosstructured al!throu"h scenarios (((( Pla Fwhat if to sim%late scenarios that ill%strate %se of a sstemPla Fwhat if to sim%late scenarios that ill%strate %se of a sstem

Let each &erson 'e res&onsi'le for sim%lating one or more classesLet each &erson 'e res&onsi'le for sim%lating one or more classesFFE<ec%te a scenario of classes &erforming res&onsi'ilities/E<ec%te a scenario of classes &erforming res&onsi'ilities/ Start a sim%lation with the constr%ction of an o'6ect of a class)Start a sim%lation with the constr%ction of an o'6ect of a class)

then &erform one of its res&onsi'ilities -a 'eha*ior.then &erform one of its res&onsi'ilities -a 'eha*ior.  + res&onsi'ilit ma &ass control to a colla'orator another class‑‑ + res&onsi'ilit ma &ass control to a colla'orator another class‑‑

Sim%lation 'ecomes *isi'le as a sharing of res&onsi'ilitiesSim%lation 'ecomes *isi'le as a sharing of res&onsi'ilities Jo% ma disco*er missing or incom&letel descri'ed res&onsi'ilitiesJo% ma disco*er missing or incom&letel descri'ed res&onsi'ilities See foot'all e<am&le in m%ltimediaSee foot'all e<am&le in m%ltimedia

$MO) it reall sho%ld 'e called res&onsi'ilit(dri*en$MO) it reall sho%ld 'e called res&onsi'ilit(dri*en analysis,analysis,rather than res&onsi'ilit(dri*enrather than res&onsi'ilit(dri*en designdesign00

Why? When is responsibility driven activity most useful?Why? When is responsibility driven activity most useful?

Page 17: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 17/34

Class "iagram 5otation !arsClass "iagram 5otation !arsEarl ?K1s/ D(K different notationsEarl ?K1s/ D(K different notations Bertrand Meer/ circles and arrowsBertrand Meer/ circles and arrows

 "isting%ishes inheritance and client@s%&&lier relationshi&s"isting%ishes inheritance and client@s%&&lier relationshi&s Grad Booch/ clo%ds) lines and decorationsGrad Booch/ clo%ds) lines and decorations

 GardeningPlan +ssociation( En*ironmental Controller GardeningPlan +ssociation( En*ironmental Controller 

 eater and Cooler Generali:ation@S&eciali:ation( +ct%ator eater and Cooler Generali:ation@S&eciali:ation( +ct%ator 

 En*ironmental ControllerEn*ironmental Controller NN(Fhas a( eater -Cooler) Light.(Fhas a( eater -Cooler) Light.

 +ct%ator o F%sing 8em&erat%re -client@s%&&lier. +ct%ator o F%sing 8em&erat%re -client@s%&&lier.

 +ct%ator is an a'stract class -;+1 in a triangle. +ct%ator is an a'stract class -;+1 in a triangle. Peter Coad) Ed Jo%rdon ill 5icola/Peter Coad) Ed Jo%rdon ill 5icola/

Ro%nded 'o<es and annotated linesRo%nded 'o<es and annotated lines Line 'isected ' semi(circle re&resents generali:ationLine 'isected ' semi(circle re&resents generali:ation

 Line 'isected ' triangle re&resents whole@&artLine 'isected ' triangle re&resents whole@&art So) what1s o%r reaction to all these -and more. notations#So) what1s o%r reaction to all these -and more. notations#

 FFCan1t we all get along#Can1t we all get along#

ence three amigos create UML in mid(?K1sence three amigos create UML in mid(?K1s

Page 18: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 18/34

Closer loo at Coad 5icolaCloser loo at Coad 5icola

8wo different 'o<es gro%&ing classes/8wo different 'o<es gro%&ing classes/ $C -%man $nteraction Com&onent.$C -%man $nteraction Com&onent. P"C -Pro'lem "omain Com&onents.P"C -Pro'lem "omain Com&onents. !h is FSe&aration of Concerns &rinci&le a good idea#!h is FSe&aration of Concerns &rinci&le a good idea#

7irst &erson scenarios/7irst &erson scenarios/

Coad 5icola call this the QCoad 5icola call this the Q

I'm aliveI'm alive

 &rinci&leQ/&rinci&leQ/

O'6ects can 'e 'etter %nderstood ' thining a'o%t them andO'6ects can 'e 'etter %nderstood ' thining a'o%t them andtaling a'o%t them in the first &erson/taling a'o%t them in the first &erson/

Q$ now m own HHHH and $ can HHH mself0QQ$ now m own HHHH and $ can HHH mself0Q !hat goes in the 'lans#!hat goes in the 'lans#

 +ttri'%tes and 'eha*iors +ttri'%tes and 'eha*iors !h is &%tting these scenarios in the first &erson a good idea#!h is &%tting these scenarios in the first &erson a good idea#

FFO'6ect(thin/ o'6ects are a%tonomo%s) &erform 'eha*iorsO'6ect(thin/ o'6ects are a%tonomo%s) &erform 'eha*iors

Similarl) Aent Bec tals a'o%t the need for anthro&omor&hismSimilarl) Aent Bec tals a'o%t the need for anthro&omor&hismin res&onsi'ilit(dri*en designin res&onsi'ilit(dri*en design

Page 19: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 19/34

Class diagrams in UMLClass diagrams in UML

Classes are 'o<es) lines are associationsClasses are 'o<es) lines are associations  +dd decorations to lines to refine them +dd decorations to lines to refine them

B%t 'efore we st%d the decorations0B%t 'efore we st%d the decorations0

Page 20: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 20/34

 + he%ristic for class diagram design + he%ristic for class diagram design

Don't put any decorations on the associations at first Don't put any decorations on the associations at first 

 Semantics of relations tends to 'eSemantics of relations tends to 'e vaguevague FF$s aQ relationshi& can mean SUB8JPE -Qa s>%are is a &olgonQ.$s aQ relationshi& can mean SUB8JPE -Qa s>%are is a &olgonQ. or $5S8+5CE O7 -QGeorge is a s>%areQ.‑or $5S8+5CE O7 -QGeorge is a s>%areQ.‑

or $"E58$C+L 8O -Q8he morning star is the e*ening starQ.‑or $"E58$C+L 8O -Q8he morning star is the e*ening starQ.‑

or PROPER8J O7 -Q+ circle is a ro%nd o'6ectQ.‑

or PROPER8J O7 -Q+ circle is a ro%nd o'6ectQ.‑

or ROLE O7 -QGeorge is a PresidentQ.‑or ROLE O7 -QGeorge is a PresidentQ.‑

or M+"E O7 -QM ho%se is a 'ric oneQ.‑or M+"E O7 -QM ho%se is a 'ric oneQ.‑

or sim&l E$S8S -F8o 'e or not to 'eQ.0or sim&l E$S8S -F8o 'e or not to 'eQ.0 $n man lang%ages) there is no *er' QisQ at all) or it1s rarel %sed0$n man lang%ages) there is no *er' QisQ at all) or it1s rarel %sed0

Let the meaning of relationsLet the meaning of relations emergeemerge from what the relatefrom what the relate ag%eness is nat%ral/ start off *ag%e) get more s&ecific grad%allag%eness is nat%ral/ start off *ag%e) get more s&ecific grad%all

UML s%&&orts this he%ristic ' starting with sim&leUML s%&&orts this he%ristic ' starting with sim&le%ndirected lines -associations.%ndirected lines -associations.

Later) add detail to o%r relationshi& str%ct%resLater) add detail to o%r relationshi& str%ct%res

Page 21: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 21/34

8wo 'asic relationshi&s of O(O8wo 'asic relationshi&s of O(O

OO+ t&icall disting%ishes two relations/OO+ t&icall disting%ishes two relations/ is a‑is a‑  andand has a‑has a‑

!h!h twotwo##

8hat1s what O(O &rogramming lang%ages im&lement/8hat1s what O(O &rogramming lang%ages im&lement/ Smalltal and a*a/ instance *aria'les and inheritanceSmalltal and a*a/ instance *aria'les and inheritance C/ data mem'ers and class deri*ationC/ data mem'ers and class deri*ation

Meer calls theseMeer calls these inheritanceinheritance andand client#supplier client#supplier 

Booch/Booch/ "enerali$ation#speciali$ation"enerali$ation#speciali$ation andandassociationassociation oror a""re"ationa""re"ation oror compositioncomposition

Coad and Jo%rdon/Coad and Jo%rdon/ "en#spec"en#spec andand hole#parthole#part

UML calls theseUML calls these "enerali$ation"enerali$ation andand associationassociation oror a""re"ationa""re"ation oror compositioncomposition

Page 22: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 22/34

 +ssociations + lin 'etween two classes -Fhas a. 8&icall modeled as a mem'er reference8&icall modeled as a mem'er reference 5otation from E<tended Entit Relation -EER. models5otation from E<tended Entit Relation -EER. models

 + Person wors for a Com&an

Role names and m%lti&licit at association ends

"irection arrow to aid reading of association name

Person   Company

employee   employer

works for

Association Name

Role

K00T

Page 23: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 23/34

Generali:ation @ S&eciali:ation

Classes ma 'e s%'classes of other classes Fa ind of or Fis a

Cars are a ind of *ehicle -Or a car is a *ehicle.

Chairs are a ind of f%rnit%re

Peo&le are a ind of mammal

Generali:ation ca&t%res commonalit/ !hat do cars ha*e in common with *ehicles#

Same &ro&erties and 'eha*iors

UML/ generali:ation@s&eciali:ation relationshi& "rawn as a line with an arrow head on one end

$nheritance in OO &rogramming lang%ages

Page 24: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 24/34

Generali:ation E<am&le

Page 25: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 25/34

 +d*antages of $nheritance#

OOP " t ' t ti

Page 26: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 26/34

OOP "ata a'straction

inheritance

dnamic 'inding -&olmor&hism.Polmor&hism/ a f%nction can do different 'eha*iors at r%ntime

"namic 'inding/ dela f%nction 'inding to a s%'t&e %ntil r%ntime

S%&&ose we want to draw a heterogeneo%s collection of sha&es#

  class Point V 000 W, @@a Point has < and coordinates

class Sha&e V

&rotected/ @@accessi'le to s%'classes '%t otherwise &ri*ate

Point center, @@all Sha&es ha*e a center Point

  &%'lic/

Point where-. V ret%rn center, W @@earl 'inding ' defa%lt

virtual *oid mo*e-Point to. @@can o*erride virtual f%nction

 V center to, draw-., W @@ ' deri*ed classes

virtual *oid draw()%&, @@K is a Q&%reQ *irt%al f%nction

@@draw-. must  'e im&lemented ' deri*ed classes

@@000

W,

@@!h do we sa Sha&e is an abstract  class#

Page 27: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 27/34

S%'classes o*erride

*irt%al f%nctions

class 8riangle/ &%'lic Sha&e VPoint sw) se) to&, @@8hree &oints define triangle

  &%'lic/

8riangle-Point a) Point ') Point c. / sw-a.) se-'.) to&-c. VW

draw() //implementing pure virtual function

  V &%tHline-sw)to&., @@draw line from sw to to&  &%tHline-to&)se., @@draw line from to& to se

  &%tHline-se)sw., @@draw line from se to sw

  W

W,

class Circle / &%'lic Sha&e V

int radi%s,

  &%'lic/

Circle-Point a) int r. / center-a.) radi%s-r. VW

draw() //draw a circle using center and radiusW,

Page 28: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 28/34

Calling a *irt%al f%nction

V @@Constr%ct some sha&es

Sha&e aSha&e, @@illegal((wh#Circle c-Point-2K)3K.)X., @@legal((what does it do#

@@Create an arra of *ario%s sha&es

Sha&eT sha&esYKZ, @@!h is this legal#

sha&esYKZ new Circle-Point-2K)3K.)X., @@assign a Circlesha&esYZ new 8riangle-Point-K)K.)Point-3K)3K.)Point-4K)4K..,

@@000 ma'e assign other sha&es) Rectangles) S>%ares) etc0

for -int iK, i [ K, i. @@draw all the sha&es

  sha&esYiZ(draw-., @@each sha&e draws itselfI

W

!h do we sa that elements of sha&es arra are pol'morphic#

Polmor&hic design s%&&orts B0 Meer1s O&en(Closed &rinci&le/

 + mod%le sho%ld 'e o&en to e<tension '%t closed to modification So im&ortant that it1s '%ilt into most OO &rogramming lang%ages

Page 29: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 29/34

!h dnamic 'inding#

!hat ind of code does dnamic 'inding a*oid#  +*oids lots of switch statements) e0g0/

switch -sha&esYiZ(isa.

@@each Sha&e deri*ed class has an isa data mem'er 

V case-triangle. 8riangle//draw-., @@test en%merationcase-circle. Circle//draw-., @@r%n s&ecific draw-.

@@ 000

W

!h is the dnamic 'inding *ersion 'etter for'ig) growing &rograms#

Man design &atterns '%ild on &olmor&hism

Page 30: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 30/34

7i*e acti*ities of OO+7i*e acti*ities of OO+

Coad) Jo%rdon and 5icola/Coad) Jo%rdon and 5icola/

. Class o'6ect/ descri'e &ro'lem domain‑ ‑. Class o'6ect/ descri'e &ro'lem domain‑ ‑

in terms of classes of o'6ectsin terms of classes of o'6ects

2. Str%ct%re/ descri'e relationshi&s 'etween classes2. Str%ct%re/ descri'e relationshi&s 'etween classes3. S%'6ect/ organi:e classes into cl%sters or &acages3. S%'6ect/ organi:e classes into cl%sters or &acages

4. +ttri'%tes/ descri'e data held ' o'6ects4. +ttri'%tes/ descri'e data held ' o'6ects

. Ser*ices/ descri'e 'eha*iors that o'6ects can &erform. Ser*ices/ descri'e 'eha*iors that o'6ects can &erform

!hich of these fi*e acti*ities are analsis!hich of these fi*e acti*ities are analsisand which are design#and which are design#

Page 31: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 31/34

Concrete and a'stract classesConcrete and a'stract classes

$dentifing classes is st acti*it of domain analsis$dentifing classes is st acti*it of domain analsis

Remem'er the ling%istic analsis techni>%eRemem'er the ling%istic analsis techni>%e

Can ignore inheritance and &olmor&hism for firstCan ignore inheritance and &olmor&hism for first

draft) then factor o%t commonalit as s%&erclassesdraft) then factor o%t commonalit as s%&erclasses

 +n +n abstractabstract class has one or more o&erationsclass has one or more o&erations

thatthat must must  'e im&lemented ' s%'classes'e im&lemented ' s%'classes

UML re&resents an a'stract classUML re&resents an a'stract class'' italici!ing italici!ing  the class namethe class name

or adding the constraint la'elor adding the constraint la'el abstractabstract

Page 32: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 32/34

Str%ct%re -association. analsisStr%ct%re -association. analsisLines connecting classesLines connecting classes

$n UML) sim&le line is an$n UML) sim&le line is an associationassociation "ecorations for m%lti&licit) role names) constraints"ecorations for m%lti&licit) role names) constraints

See e<am&le from 7owler See e<am&le from 7owler  !hat does VorderedW constraint mean#!hat does VorderedW constraint mean#

 +ggregations and com&osition/ +ggregations and com&osition/  +rrow denotes na*iga'ilit +rrow denotes na*iga'ilit e0g0) Polgon and Circle refer to Point '%t not *ice *ersae0g0) Polgon and Circle refer to Point '%t not *ice *ersa  + + blac!blac!((filledfilled diamond denotes adiamond denotes a compositioncomposition 

a &art)a &art) uni*ueuni*ue to this wholeto this whole  + + hitehite((empt'empt' diamond denotes andiamond denotes an a""re"ationa""re"ation 

a &art) '%t not %ni>%e to this wholea &art) '%t not %ni>%e to this whole E0g0) + Point ma a&&ear in onlE0g0) + Point ma a&&ear in onl oneone Polgon or CirclePolgon or Circle

'%t a Stle co%ld a&&ear in 'oth'%t a Stle co%ld a&&ear in 'oth

 +n alternati*e notation for com&osition in 'o<es +n alternati*e notation for com&osition in 'o<es

Page 33: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 33/34

 +ttri'%tes and o&erations +ttri'%tes and o&erations

 + class 'o< ma ha*e three &arts + class 'o< ma ha*e three &arts Class name) attri'%tes and o&erationsClass name) attri'%tes and o&erations

 +ttri'%tes in middle section +ttri'%tes in middle section 8&icall attri'%tes are '%ilt(in t&es8&icall attri'%tes are '%ilt(in t&es

UML lets o% incl%de information a'o%t defa%lt *al%esUML lets o% incl%de information a'o%t defa%lt *al%esand *isi'ilit -)()\.and *isi'ilit -)()\.

E0g0) ( name/ String YZ FUntitled VreadonlWE0g0) ( name/ String YZ FUntitled VreadonlW

 &ri*ate / t&e m%lti&licit defa%lt V&ro&ertW&ri*ate / t&e m%lti&licit defa%lt V&ro&ertW-%nmodifia'le.-%nmodifia'le.

$ recommend o% hold off on these details %ntil design$ recommend o% hold off on these details %ntil design

O&erations in 'ottom section of class 'o<O&erations in 'ottom section of class 'o< Re&resent ser*ices) f%nctions or methodsRe&resent ser*ices) f%nctions or methods  +gain) UML has a 'it more notation) +gain) UML has a 'it more notation)

for information a'o%t &arameters) defa%lt *al%es and *isi'ilitfor information a'o%t &arameters) defa%lt *al%es and *isi'ilitE0g0) 'alanceOn-date/"ate./ MoneE0g0) 'alanceOn-date/"ate./ Mone

 +gain) $ recommend o% hold off on these details %ntil design +gain) $ recommend o% hold off on these details %ntil design

Page 34: 05DomainModel UML

8/17/2019 05DomainModel UML

http://slidepdf.com/reader/full/05domainmodel-uml 34/34

Ecli&se with &l%g(insEcli&se with &l%g(ins

O&en So%rce $"E for O(O and a*aO&en So%rce $"E for O(O and a*a Pl%g(ins add more feat%resPl%g(ins add more feat%res

"ra*a &l%g(in &ro*ides a*a inter&reter "ra*a &l%g(in &ro*ides a*a inter&reter 

Pl%g(in adds UML class diagramsPl%g(in adds UML class diagrams

 +*aila'le on cam&%s ' r%nning Fecli&s +*aila'le on cam&%s ' r%nning Fecli&s

 +lso a*aila'le for download/ +lso a*aila'le for download/

htt&/@@www0lehigh0ed%@stem@teams@dier%ff -30K.htt&/@@www0lehigh0ed%@stem@teams@dier%ff -30K.