Class Diagram Intro - PetcuAlexandru/openpixi GitHub Wiki
The class diagram serves the following purposes
- shows the inheritance tree of the classes
- shows which other classes a class uses
- shows the most important methods of the class
- shows the most important fields of the class
- alternatively shows all the methods and all the fields of a class
It is best to explain a class diagram on a live example; thus, we will show and discuss two class diagrams created by two different tools.
The first diagram (below) was created in DIA editor.
The most important thing about class diagram are the arrows connecting the different classes. In the above diagram we can see two types of arrows
- Generalization: Marks the inheritance.
- Composition: Marks the fact that class A holds a reference to class B and thus A uses and is dependent on B.
The composition arrows can also have a multiplicity. You can sometimes see a composition between classes A and B with a number N at B's end of the arrow (non diamond end). It means that class A holds N instances of B.
A less important part of the class diagram are the plus and minus signs you can see before the fields or methods. The minus says that the field or method is private whereas plus denotes public.
The second example of class diagram was generated from the actual code in IntelliJ Idea IDE.
In the picture above you can see one more type of arrow. It denotes a dependency and it means that class A is using class B in some of its methods.
For further information about class diagrams see wikipedia.