UML
- UML stands for the Unified Modeling Language
- It is a tool for visualizing classes
- I use the software UMLentino
- On line or download and run on your computer.
- There are others, but this works well.
- There is a brief reference in appendix D (P 1083)
- UMLentio is fairly self documenting.
- I use this book as my reference.
- This language is huge, but we will only use the class portion.
- Let's take a look at FastFood from the last assignment.
- What class should you have built?
- What are the possible "objects" in the game
- A Sticker
- The collection of stickers
- Prize
- Coach
- Team
- Which of these are real objects in the program?
- Probably not the coach and the team.
- Which have both data and operations
- A sticker are just exist or not, so they don't
- We are left with
- The collection of stickers
- A prize
- Let's start with a prize
- So what are the member operations and data of the prize
- The data is easy:
- a prize amount
- a vector of ticket id's needed.
-
- Let's do the UML for that.
-
- The Methods
- Constructor.
- Do we need the big 3?
- Add Prize, Get Prize
- Add Sticker
- We now have a decision to make
- Does a prize decided if it has been won?
- When designing classes we need to have clear lines of responsibility.
- We can put this anywhere, but we need the methods to support it.
- If yes, we need a method that takes a container of stickers and returns
- The prize value of those stickers.
- Possibly a modified sticker list with those stickers removed.
- If no, we need a way to get the list of stickers required.
- I like the second for this program.
- How about the sticker collection
- The data is an array of stickers.
- The methods
- Constructor (stickerCount)
- ChangeSticker (id, quantity)
- GetSticker(id)
-
- Let's consider a coach type.
- Data
- An array of PrizeT
- A StickerCollectionT
- Operations
- AddPrize
- AddSticker
- CalculateWinnings
-
- This is an instance of a "has a" relationship.
- A coach has a list of prizes
- A coach has a StickerCollection.
- In the first case, prizes can exist without a coach
- So this is an Aggregation
- Draw with a empty diamond from prize to coach
- This is a forced example.
- Think "a pond has a frog".
- Frogs can exist without ponds
- In the second case, let's say a sticker collection can not exist without a coach
- This is a composition
- Use a solid diamond.
- This is a forced example.
- Think "A frog has a heart".
- Outside of biology class, a heart does not exist without a frog.
- When the frog is destroyed, the heart is destroyed.
-
- Sometimes we show the diagram without details (high level)
-