Describing Classes with UML
- UML or the Unified Modeling Language
- A general purpose modeling language
- Provides a standard way to visualize the design of a system.
- There are many different types of diagrams in UML
- We will focus on Class Diagrams for now.
- Class Diagrams show the structure of a system's classes.
- A class is represented by a box with three compartments
- The class name, generally CamelCase
- The class attributes
- The data fields
- name, camelCase
- attribute type (Optional)
- Operations
- Class methods
- Name
- Parameters (optional)
- type of value returned.
- Attributes and operations can show visibility
- Starting with a + means an item is public.
- Starting with a - means an item is private.
- Starting with a # means protected visibility.
- Subclasses have access to this item
- Consider a die
- It has a number of sides.
- It has a current value.
- You can roll a die.
- You can Check the value.
-
- I am using a package called UMLet
- Or the on line version UMLetino
- This is a free package that is installed in our lab.
- Do a demo, create the die.
- A Stereotype
- Allows modification of UML.
- We need to create a new UML class to model Rolls
- So we will use a stereotype.
- Use << name >>
-
- Then list the values.
- I added the "methods" or functions available for this enumerated type.
- The Roll and Disaster Enumerations
- We could just string representation for the roll types and disaster types.
- But there is too much chance that I will spell a string wrong in comparisons
- And it takes too much space
- And it is not centralized
- Disasters are pictured above.
- Some rolls are not modified, but I think we should include them for future expansion.
- The tables use "Get +1 to Build Rolls"
- But there is no actual build roll in the document.
- I assume that this is the "Resource Roll" as resource points are used to build cities and wonders.
- So "Build" and "Resource" should both acceptable strings for this roll type.
- But the word "Build" should be output for the equivalent string.
- In both cases, there should be the following routines
- Convert a string to an enumerated value.
- Convert an enumerated value to a string.
- Overload the stream insertion operator to allow printing of the associated string.
-
- A note on implementation
- You will use Strongly Typed Enumerations to implement the two above classes.
- Page 14-15 of your book gives a discussion and an example.
- These are from c++11
- You can look up the documentation on line, but this code might help.