UML Class Diagram - m00racle/Pos-Project GitHub Wiki

This is the documentation for project progress on UML Class Diagram as seen in the Projects section.

I need to finish the Class Diagram before coding the whole apps. This will make it easier as I will have better guidelines at least on how to build programming structures.

SUMMARY AND RULES

  1. Attribute are variables declared in the class
  2. Operations are functions or methods declared in classes or interfaces
  3. Constant attribute is a variable with initial value and all CAPITAL named
  4. derived attribute is variable that does not have initial value and not initialized but derived later. This attribute use / in fron of its name.
  5. Initiated attributes are variables that its values determined (initialized) when an object based on its class is instantiated.
  6. thus it is not required to define init operation in the operation list.
  7. << get >> put in front of attribute declaration to indicate the attribute will have getter operation.
  8. << set >> put in front of attribute declaration to indicate the attribute will have setter operation.
  9. <<get/set>> put in front of attribute declaration to indicate the attribute will have getter and setter operations.

RECOMMENDATIONS

  • change all properties declaration in the class diagrams to attributes
  • chage all methods declaration in the class diagram to operations.

The main question here is on how to declare the getter and setter methods for class attributes. There are many attributes in each class thus if I need to define getter and setter one by one it will not be practical. The question now, is there any alternative ways on declaring getter and/or setter methods for classifier?

According to this Stack Overflow forum post, I can use shortcut in terms of stereotypes:

alternative getter/setter in classifier props

The use of << >> is the same as stereotype symbol in the UML 2.0 and above. I think the idea here is similar as getter and setter are can be seen as stereotypes but in method realm.

However on another webisite, researchgate, the example of the class diagram defines each getter and setter one by one as in this image:

getter and setter defiend for each method

This is less practical when attributes are a lot. Also note that in terms of inheritance and implementation the classes redo attributes declaration in each class while they implement the interface. In my opinion this is a bit redundant. However, I can understand if the reason for this redundancy is safety and clarity.

On this YouTube UML course video example the class diagram also have getter and setter method inside them.

class diagram methods example

Note that inside the methods there are no init. I think the question about init should be on other to do list.

The matter of the getter and setter will conclude which variables in the attributes that immutable and which are mutable. The variables which are do not have setter must be mutable initiated on class instantiation. Or on other situation the variables with not setter methods are CONSTANT. However, in the this YouTube course session it is also stated that in some cases declaring all getters and setters for a lot or attributes can be cumbersome that some just omit them out.

I think I will take the middle road here and uses the << >> symbols to determine which attributes has getters and/or setters.

Additional Insights

Here are some additional insights from the course:

attribute types

This shows how to put type of each attribute. There are primitive types such as int, boolean, double, etc. Also it can be other classes, libs, or packages. NOTE: The array type or list type should use [] but with 0..* if it allowed to be empty list and [1..*] if at least has to have 1 element.

attributes init values

This is what will differentiate when the attributes are constant or not. As for attributes that are derived from other attributes or result of an operation we use:

derived attributes

The derived attributes will have "/" (slash symbol) attached in front of it. This will settle the question of which attributes are initiated. Initiated attributes are the attributes with no initial value and derived types.

Operations

In the classifier diagram the functions or methods inside class or interfaces are called operations.

operations examples

I need to modify the current definition as I use properties for the attributes and methods for operations.

Similar to attributes, operations can define type. However, in the case of operations the type is the type of variable returned from each operation. The type declaration is the same as the attribute one using : symbol. If the operation returns nothing then you can just omit the type or use : Void type.

Other important aspect of operation is the parameters. Those are the variables arguments passed into the operation. To declare those parameters you need to mention the variable name and its type inside the ( ) after the operation names.

⚠️ **GitHub.com Fallback** ⚠️