1 / 22

Outline of this exercise

Outline of this exercise. Learning objectives: After this exercise, a student should be able to: Read a UML class diagram Describe the basic process for developing a UML class diagram Explain what is easy about the process and what is hard Explain the iterative nature of the design process

mimi
Download Presentation

Outline of this exercise

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Specification of BallWorld • BallWorld is just that -- a world that contains various kinds of balls • along with hotspots and perhaps other things eventually • Each of the buttons represents a Java class that you will write • Pressing a button creates a ball of that type • Types of Balls might include: • Dud: does nothing • DudThatMoves: just moves in a constant, random velocity • Dragger: the user can drag it around and kill (delete) it • Mover: like a Dragger, but moves like a MovingDud • Bouncer: like a Mover, but bounces off the walls of the World • Shrinker: A Bouncer that grows and shrinks in size • Exploder: Grows, then explodes and replicates itself! Questions? You cannot design software unless you know what it is supposed to do!

  3. Design BallWorld, by drawing a UML class diagram for it Review the specification, then: • Identify kinds of objects – these become classes • Identify relationships between classes • is-a (extends), is-a (implements), has-a • Identify interfaces that specify what is needed for the classes to relate • For each class, determine its attributes and operations • For each class, for each attribute/operation, determine its type We frequently retrace our steps and fine tune our design.

  4. List the classes in BallWorld • List the kinds of things – classes – that you think belong in the BallWorld design: • Some are visual • Some are internal • Some are relevant Java library classes like JFrame • When done, compare your list with other lists around the room

  5. The classes that I chose • Visual things: • BallWorldFrame • WorldPanel • ButtonsPanel • BallButton • A single class, with several instances with different labels • Non-visual things: • BallWorld • The class that contains main • Ball • Various subclasses of Ball • HotSpot • World • The class that manages all the Balls and HotSpots • Relevant Java library classes: • JFrame • JPanel • JButton Question: Why not just let the WorldPanel play this role? Answer: I choose to separate function from display of that function

  6. Design BallWorld, by drawing a UML class diagram for it We just did our first iteration of Step 1 Review the specification, then: • Identify kinds of objects – these become classes • Identify relationships between classes • is-a (extends), is-a (implements), has-a • Identify interfaces that specify what is needed for the classes to relate • For each class, determine its attributes and operations • For each class, for each attribute/operation, determine its type Now we’ll do our first iteration of Step 2, beginning with the is-a (extends) relationship We frequently retrace our steps and fine tune our design.

  7. 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 A B Is-arelationships JButton BallButton JFrame ButtonsPanel JPanel BallWorldFrame BallWorld WorldPanel Ball HotSpot World

  8. 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 A B Is-arelationships JButton JFrame BallButton JPanel BallWorldFrame BallWorld ButtonsPanel WorldPanel Ball World HotSpot Questions on is-a so far?

  9. 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 A B Is-arelationships • Types of Balls might include: • Dud: does nothing • MovingDud: just moves in a constant, random velocity • Dragger: the user can drag it around and kill (delete) it • Mover: like a Dragger, but moves like a MovingDud • Bouncer: like a Mover, but bounces off the walls of the World • Shrinker: A Bouncer that grows and shrinks in size • Exploder: Grows, then explodes and replicates itself! Ball Mover Dud Shrinker Dragger Exploder MovingDud Bouncer . . .

  10. 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 A B Is-arelationships • Types of Balls might include: • Dud: does nothing • MovingDud: just moves in a constant, random velocity • Dragger: the user can drag it around and kill (delete) it • Mover: like a Dragger, but moves like a MovingDud • Bouncer: like a Mover, but bounces off the walls of the World • Shrinker: A Bouncer that grows and shrinks in size • Exploder: Grows, then explodes and replicates itself! Ball Mover Dud Shrinker Dragger Exploder MovingDud Bouncer . . . Questions on is-a relationships?

  11. 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) A B Has-arelationships JButton JFrame BallButton JPanel BallWorldFrame BallWorld ButtonsPanel WorldPanel Ball World HotSpot 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.

  12. A B Has-arelationships JButton BallButton 1..* JFrame ButtonsPanel JPanel BallWorldFrame Notation: A has-a B, here, A creates a B Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1 BallWorlds WorldPanel 1..* Ball HotSpot World 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? At this point, we need to ask ourselves – what remains to be created? Who should create them? 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?

  13. A B Has-arelationships JButton BallButton 1..* JFrame ButtonsPanel JPanel BallWorldFrame Notation: A has-a B, here, A creates a B Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1 BallWorld WorldPanel 1..* Ball HotSpot World 0..* We have yet to create the Balls and HotSpots? Who should create the HotSpots? Who creates a new Ball, e.g., a new Exploder? How? Answer: the World seems a natural choice. Answer: the human user, by pressing a BallButton.

  14. A B Has-arelationships JButton BallButton 1..* JFrame ButtonsPanel JPanel BallWorldFrame Notation: A has-a B, here, A creates a B Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1 BallWorld WorldPanel 1..* Ball HotSpot World 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 Drawn In the current design, the latter two are impossible. Explain.

  15. A B Has-arelationships JButton BallButton 1..* JFrame ButtonsPanel JPanel BallWorldFrame Notation: A has-a B, here, A creates a B Indicate the multiplicity on each end: 1 .. * (one or more), blank for exactly 1 BallWorld WorldPanel 1..* Ball HotSpot World 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 Drawn In 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?

  16. is-a JButton Relationships has-a BallButton 1..* ButtonsPanel JFrame 1..* JPanel • 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? BallWorldFrame 1..* WorldPanel BallWorld 1..* Draw links to enable the construct/add/draw actions. Revise your answers to the “who-should” questions as needed, as you design. World Ball Dud Bouncer Bloater Exploder . . .

  17. is-a JButton Relationships has-a BallButton 1..* ButtonsPanel JFrame 1..* JPanel 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. BallWorldFrame 1..* WorldPanel BallWorld 1..* BallButton: construct the new Ball. No links needed. (Why?) World BallButton: tell the World to add the Ball. What does that imply is needed in the diagram? Ball Dud Bouncer Bloater Exploder . . .

  18. is-a JButton Relationships has-a BallButton 1..* ButtonsPanel JFrame 1..* JPanel • 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? BallWorldFrame 1..* WorldPanel BallWorld 1..* World BallButton: construct the new Ball. No links needed. How does the BallButton obtain the World? Ball 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? Dud Bouncer Bloater Exploder . . .

  19. is-a JButton Relationships has-a BallButton 1..* ButtonsPanel JFrame 1..* JPanel The World is intended to hold all of the balls. What has-a does that imply? Draw it. BallWorldFrame 1..* WorldPanel BallWorld 1..* World Who creates a new Ball, e.g., a new Exploder? How? Answer: the human user, by pressing a BallButton. 1..* Ball Dud Bouncer Bloater Exploder . . .

  20. is-a JButton Relationships has-a BallButton 1..* ButtonsPanel JFrame 1..* JPanel Drawable interface BallWorldFrame 1..* WorldPanel BallWorld WorldManagement interface 1..* Animatable interface World 1..* Ball What about interfaces? – This is a chance to give the design strategic consistency by defining up front how the interacting entities should talk! Dud Bouncer Bloater Exploder . . .

  21. More questions • Attributes: • What does a Ball have? • When the human user clicks a BallButton, should the World become aware of the constructed Ball? If so, how? • How is drawing done? • WorldPanel gives info to Ball, or Ball gives info to WorldPanel? • How do Balls “act”? What else should the human user be able to do to Balls? How is that accomplished? • Who should act independently (i.e., what threads should exist)? • What interfaces would be useful in the above? In particular, what should the following be able to do: • Ball HotSpot ManagerOfBalls ManagerOfHotSpots

  22. Design BallWorld, by drawing a UML class diagram for it We just did our first iteration of Step 1 & 2 Review the specification, then: • Identify kinds of objects – these become classes • Identify relationships between classes • is-a (extends), is-a (implements), has-a • Identify interfaces that specify what is needed for the classes to relate • For each class, determine its attributes and operations • For each class, for each attribute/operation, determine its type Now we’ll continue with our first iteration of Step 3 & 4 We frequently retrace our steps and fine tune our design.

More Related