fundamentals of software development 1slide 1 outline of this exercise learning objectives:learning...

22
Fundamentals of Softw are Development 1 Slide 1 Outline of this exercise Outline of this exercise Learning objectives: Learning objectives: After this exercise, a student should be able After this exercise, a student should be able to: to: Read a UML class diagram Read a UML class diagram Describe the basic process for developing a UML class Describe the basic process for developing a UML class diagram diagram Explain what is easy about the process and what is Explain what is easy about the process and what is hard hard Explain the iterative nature of the design process Explain the iterative nature of the design process Process: Process: Review the specification of BallWorld Review the specification of BallWorld Develop a UML class diagram for BallWord Develop a UML class diagram for BallWord Together (in groups), step by step Together (in groups), step by step

Upload: franklin-barrett

Post on 18-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Fundamentals of Software Development 1

Slide 1

Outline of this exerciseOutline of this exercise

• Learning objectives:Learning objectives:– After this exercise, a student should be able to:After this exercise, a student should be able to:

• Read a UML class diagramRead a UML class diagram• Describe the basic process for developing a UML class Describe the basic process for developing a UML class

diagramdiagram• Explain what is easy about the process and what is Explain what is easy about the process and what is

hardhard• Explain the iterative nature of the design processExplain the iterative nature of the design process

• Process:Process:– Review the specification of BallWorldReview the specification of BallWorld– Develop a UML class diagram for BallWordDevelop a UML class diagram for BallWord

• Together (in groups), step by stepTogether (in groups), step by step

Fundamentals of Software Development 1

Slide 2

Specification of BallWorldSpecification of BallWorld• BallWorld is just that -- a BallWorld is just that -- a

world that contains various world that contains various kinds of kinds of ballsballs– along with along with hotspotshotspots and and

perhaps other things perhaps other things eventuallyeventually

• Each of the buttons Each of the buttons represents a Java class represents a Java class that you will writethat you will write– Pressing a button creates a Pressing a button creates a

ball of that typeball of that type• Types of Balls might include:Types of Balls might include:

– DudDud: does nothing: does nothing– DudThatMovesDudThatMoves: just : just

moves in a constant, random moves in a constant, random velocityvelocity

– DraggerDragger: the user can drag : the user can drag it around and kill (delete) itit around and kill (delete) it

– MoverMover: like a Dragger, but : like a Dragger, but moves like a MovingDudmoves like a MovingDud

Questions? You cannot design software unless you know what it is supposed to do!

– BouncerBouncer: like a Mover, but bounces off the walls of : like a Mover, but bounces off the walls of the Worldthe World

– ShrinkerShrinker: A Bouncer that grows and shrinks in size: A Bouncer that grows and shrinks in size– ExploderExploder: Grows, then explodes and replicates : Grows, then explodes and replicates

itself!itself!

Fundamentals of Software Development 1

Slide 3

Design BallWorld, by Design BallWorld, by drawing a UML class drawing a UML class

diagram for itdiagram for itReview the specification, then:Review the specification, then:1.1. Identify kinds of objects – these Identify kinds of objects – these

become become classes classes 2.2. Identify Identify relationshipsrelationships between between

classesclasses• is-a is-a (extends), (extends), is-ais-a (implements), (implements), has-has-

aa• Identify Identify interfacesinterfaces that specify what is that specify what is

needed for the classes to relateneeded for the classes to relate3.3. For each class, determine its For each class, determine its

attributesattributes and and operationsoperations4.4. For each class, for each For each class, for each

attribute/operation, determine its attribute/operation, determine its typetype

We frequently retrace our steps and fine tune

our design.

Fundamentals of Software Development 1

Slide 4

List the List the classes in classes in BallWorldBallWorld

• List the kinds of List the kinds of things – classes – things – classes – that you think that you think belong in the belong in the BallWorld BallWorld design:design:– Some are visualSome are visual– Some are internalSome are internal– Some are Some are

relevant Java relevant Java library classes library classes like JFramelike JFrame

• When done, When done, compare your list compare your list with other lists with other lists around the roomaround the room

Fundamentals of Software Development 1

Slide 5

The The classes classes that I that I chosechose• Visual things:Visual things:

– BallWorldFrameBallWorldFrame– WorldPanelWorldPanel– ButtonsPanelButtonsPanel– BallButtonBallButton

• A A singlesingle class, class, with several with several instances with instances with different labelsdifferent labels • Non-visual things:Non-visual things:

– BallWorldBallWorld• The class that contains The class that contains mainmain

– BallBall– Various Various subclassessubclasses of Ball of Ball– HotSpotHotSpot– WorldWorld

• The class that manages all the Balls and HotSpotsThe class that manages all the Balls and HotSpots

• Relevant Java Relevant Java library classes:library classes:– JFrameJFrame– JPanelJPanel– JButtonJButton

Question: Why not just let the WorldPanel play this role?

Answer: I choose to separate function from display of that function

Fundamentals of Software Development 1

Slide 6

Design BallWorld, by Design BallWorld, by drawing a UML class drawing a UML class

diagram for itdiagram for itReview the specification, then:Review the specification, then:1.1. Identify kinds of objects – these Identify kinds of objects – these

become become classes classes 2.2. Identify Identify relationshipsrelationships between between

classesclasses• is-a is-a (extends), (extends), is-ais-a (implements), (implements), has-has-

aa• Identify Identify interfacesinterfaces that specify what is that specify what is

needed for the classes to relateneeded for the classes to relate3.3. For each class, determine its For each class, determine its

attributesattributes and and operationsoperations4.4. For each class, for each For each class, for each

attribute/operation, determine its attribute/operation, determine its typetype

We frequently retrace our steps and fine tune

our design.

We just did our first iteration of Step 1

Now we’ll do our first iteration of

Step 2, beginning

with the is-a (extends)

relationship

Fundamentals of Software Development 1

Slide 7

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrameButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall HotSpotHotSpot

Is-aIs-a relationshirelationshi

psps

Draw the is-a relationships between the classes shown

Notation:

A is-a B, that is, A extends B

This means that A inherits all the attributes (data) and operations (behaviors) of B

AA BB

Fundamentals of Software Development 1

Slide 8

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame

ButtonsPanelButtonsPanel WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

Questions on is-a so far?

Is-aIs-a relationshirelationshi

psps

WorldWorld

BallBall

HotSpotHotSpot

Draw the is-a relationships between the classes shown

Notation:

A is-a B, that is, A extends B

This means that A inherits all the attributes (data) and operations (behaviors) of B

AA BB

Fundamentals of Software Development 1

Slide 9

BallBall

DudDud

BouncerBouncer

ShrinkerShrinker

ExploderExploder

. . .. . .

MovingDudMovingDud

DraggerDragger

Is-aIs-a relationshirelationshi

psps• Types of Balls might Types of Balls might

include:include:– DudDud: does nothing: does nothing– MovingDudMovingDud: just moves in : just moves in

a constant, random velocitya constant, random velocity– DraggerDragger: the user can : the user can

drag it around and kill drag it around and kill (delete) it(delete) it

– MoverMover: like a Dragger, but : like a Dragger, but moves like a MovingDudmoves like a MovingDud

– BouncerBouncer: like a Mover, but bounces off the walls of : like a Mover, but bounces off the walls of the Worldthe World

– ShrinkerShrinker: A Bouncer that grows and shrinks in size: A Bouncer that grows and shrinks in size– ExploderExploder: Grows, then explodes and replicates : Grows, then explodes and replicates

itself!itself!

MoverMoverDraw the is-a relationships between the types of Balls

Notation:

A is-a B, that is, A extends B

This means that A inherits all the attributes (data) and operations (behaviors) of B

AA BB

Fundamentals of Software Development 1

Slide 10

BallBall

DudDud

BouncerBouncer

ShrinkerShrinker

ExploderExploder

. . .. . .

MovingDudMovingDud

DraggerDragger

Is-aIs-a relationshirelationshi

psps• Types of Balls might Types of Balls might

include:include:– DudDud: does nothing: does nothing– MovingDudMovingDud: just moves in : just moves in

a constant, random velocitya constant, random velocity– DraggerDragger: the user can : the user can

drag it around and kill drag it around and kill (delete) it(delete) it

– MoverMover: like a Dragger, but : like a Dragger, but moves like a MovingDudmoves like a MovingDud

– BouncerBouncer: like a Mover, but bounces off the walls of : like a Mover, but bounces off the walls of the Worldthe World

– ShrinkerShrinker: A Bouncer that grows and shrinks in size: A Bouncer that grows and shrinks in size– ExploderExploder: Grows, then explodes and replicates : Grows, then explodes and replicates

itself!itself!

MoverMover

Questions on is-a relationships?

Draw the is-a relationships between the types of Balls

Notation:

A is-a B, that is, A extends B

This means that A inherits all the attributes (data) and operations (behaviors) of B

AA BB

Fundamentals of Software Development 1

Slide 11

Has-aHas-a relationshirelationshi

psps

Draw the has-a relationships in which objects are created, for the classes shown

Notation:

A has-a B, here, A creates a B

Indicate the multiplicity on each end:

1 .. * (one or more) 3 (exactly 3) (blank often means 1)

AA BB

We also use color (here, lime green, but more often I use red) to indicate has-a relationships that involve object creation. This is not standard UML.

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame

ButtonsPanelButtonsPanel WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall

HotSpotHotSpot

Fundamentals of Software Development 1

Slide 12

BallWorldFrameBallWorldFrame

BallWorldsBallWorlds

JFrameJFrameButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButtonHas-aHas-a relationshirelationshi

psps

WorldWorld

BallBall HotSpotHotSpot 1..*

1..*

I chose to have the BallWorlds create each World, which creates the two panels (WorldPanel and ButtonPanel). Why? Who else might I have chosen to create the World? The Panels?

Part of an answer: I envision a single frame, but possibly many Worlds and associated Panels. Do you see why that leads to my choices?

At this point, we need to ask ourselves – what remains to be created? Who should create them?

Notation:

A has-a B, here, A creates a B

Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1

AA BB

Fundamentals of Software Development 1

Slide 13

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrameButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButtonHas-aHas-a relationshirelationshi

psps

WorldWorld

BallBall HotSpotHotSpot 1..*

1..*

We have yet to create the Balls and HotSpots? Who should create the HotSpots?

Notation:

A has-a B, here, A creates a B

Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1

AA BB

0..*

Answer: the World seems a natural choice.

Who creates a new Ball, e.g., a new Exploder? How?

Answer: the human user, by pressing a BallButton.

Fundamentals of Software Development 1

Slide 14

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrameButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButtonHas-aHas-a relationshirelationshi

psps

WorldWorld

BallBall HotSpotHotSpot 1..*

1..*

Notation:

A has-a B, here, A creates a B

Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1

AA BB

0..*

So the human user creates each Ball (e.g. an Exploder), by pressing a BallButton.When the human presses a BallButton, a Ball of the appropriate type must be: Constructed Added to the World DrawnIn the current design, the latter two are impossible. Explain.

Fundamentals of Software Development 1

Slide 15

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrameButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButtonHas-aHas-a relationshirelationshi

psps

WorldWorld

BallBall HotSpotHotSpot 1..*

1..*

Notation:

A has-a B, here, A creates a B

Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1

AA BB

0..*

So the human user creates each Ball (e.g. an Exploder), by pressing a BallButton.When the human presses a BallButton, a Ball of the appropriate type must be: Constructed Added to the World DrawnIn the current design, the latter two are impossible. Draw the has-a relationships that are needed – who needs to know whom? These are has-a relationships, but do NOT involve creation of objects. How are these relationships going to be implemented?

Fundamentals of Software Development 1

Slide 16

RelationsRelationshipships

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame ButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall

DudDud BouncerBouncer BloaterBloater ExploderExploder . . .. . .

is-ahas-a

1..*

1..*

1..*

1..*

Draw links to enable the construct/add/draw actions. Revise your answers to the “who-should” questions as needed, as you design.

When a new Ball is created, it must be:

• Constructed

• Added to the World

• Drawn

Who should construct the Ball? Add it to the World? Draw it?

Fundamentals of Software Development 1

Slide 17

RelationsRelationshipships

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame ButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall

DudDud BouncerBouncer BloaterBloater ExploderExploder . . .. . .

is-ahas-a

1..*

1..*

1..*

1..*

Draw links to enable the construct/add/draw actions. Revise your answers to the “who-should” questions as needed, as you design.

Here are my decisions, as I made them.

BallButton: construct the new Ball. No links needed. (Why?)

BallButton: tell the World to add the Ball. What does that imply is needed in the diagram?

Fundamentals of Software Development 1

Slide 18

RelationsRelationshipships

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame ButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall

DudDud BouncerBouncer BloaterBloater ExploderExploder . . .. . .

is-ahas-a

1..*

1..*

1..*

1..*

BallButton: construct the new Ball. No links needed.

BallButton: tell the World to add the Ball. Hence:

• BallButton must have the World

• World must be able to add a Ball

What has-a relationships does that imply need to be added, for the BallButton to have the World?

How does the BallButton obtain the World?

Answer: BallWorldFrame creates the World, then sends it to the ButtonsPanel, who sends it to each BallButton. Do you see why it was a good decision for BallWorldFrame to create the 3 big things?

Fundamentals of Software Development 1

Slide 19

RelationsRelationshipships

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame ButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall

DudDud BouncerBouncer BloaterBloater ExploderExploder . . .. . .

is-ahas-a

1..*

1..*

1..*

1..*

1..*

The World is intended to hold all of the balls. What has-a does that imply? Draw it.

Who creates a new Ball, e.g., a new Exploder? How?

Answer: the human user, by pressing a BallButton.

Fundamentals of Software Development 1

Slide 20

RelationsRelationshipships

BallWorldFrameBallWorldFrame

BallWorldBallWorld

JFrameJFrame ButtonsPanelButtonsPanel

WorldPanelWorldPanel

JPanelJPanel

BallButtonBallButton

JButtonJButton

WorldWorld

BallBall

DudDud BouncerBouncer BloaterBloater ExploderExploder . . .. . .

Animatable interfaceWorldManagement interface

Drawable interface

is-ahas-a

1..*

1..*

1..*

1..*

1..*

What about interfaces? – This is a chance to give the design strategic consistency by defining up front how the interacting entities should talk!

Fundamentals of Software Development 1

Slide 21

More questionsMore questions• Attributes:Attributes:

– What does a Ball have?What does a Ball have?

• When the human user clicks a BallButton, should the When the human user clicks a BallButton, should the World become aware of the constructed Ball? If so, how?World become aware of the constructed Ball? If so, how?

• How is drawing done?How is drawing done?– WorldPanel gives info to Ball, or Ball gives info to WorldPanel?WorldPanel gives info to Ball, or Ball gives info to WorldPanel?

• How do Balls “act”? What else should the human user be How do Balls “act”? What else should the human user be able to do to Balls? How is that accomplished?able to do to Balls? How is that accomplished?

• Who should act independently (i.e., what threads should Who should act independently (i.e., what threads should exist)?exist)?

• What interfaces would be useful in the above? In What interfaces would be useful in the above? In particular, what should the following be able to do:particular, what should the following be able to do:– Ball HotSpot ManagerOfBalls Ball HotSpot ManagerOfBalls

ManagerOfHotSpotsManagerOfHotSpots

Fundamentals of Software Development 1

Slide 22

Design BallWorld, by Design BallWorld, by drawing a UML class drawing a UML class

diagram for itdiagram for itReview the specification, then:Review the specification, then:1.1. Identify kinds of objects – these Identify kinds of objects – these

become become classes classes 2.2. Identify Identify relationshipsrelationships between between

classesclasses• is-a is-a (extends), (extends), is-ais-a (implements), (implements), has-has-

aa• Identify Identify interfacesinterfaces that specify what is that specify what is

needed for the classes to relateneeded for the classes to relate3.3. For each class, determine its For each class, determine its

attributesattributes and and operationsoperations4.4. For each class, for each For each class, for each

attribute/operation, determine its attribute/operation, determine its typetype

We frequently retrace our steps and fine tune

our design.

We just did our first iteration of Step 1 & 2

Now we’ll continue with our

first iteration of Step 3 & 4