Elements in Class Diagram:
A class diagram is composed primarily of the following elements that represent the system's business entities:
Figure 5.1 The Structure of a Class
The top compartment shows the class name. The middle compartment list the class's attributes. The bottom compartment lists the class's operations. When drawing a class element in class diagram, you must use the top compartment, and bottom two compartments are optional.
Figure 5.2 shows a circle modeled as class.
Figure 5.2 A Circle class showing name, attributes, and methods
Class Attributes List
The attribute section of a class lists each of the class's attributes on a separate line. The attribute section is optional, but when is used it contains attribute of the class displayed in a list format. The syntax is:
name: attribute typeIn business class diagrams, the attribute types usually correspond to units that make sense to the likely readers of the diagram (i. e., minutes, cm, etc.). However, a class diagram that will be used to generate code needs classes whose attribute types are limited to the types provided by the programming language, or types included in the model that will also be implemented in the system.
Sometimes it is useful to show on a class diagram that a particular attribute has a default value. The attributes with default value can be shown as below:
name: attribute type = default valueFor e. g., itsCenter: Point = (0, 0)
Showing a default value is optional.
Class Operations List
The class's operations are documented in the third compartment of the class diagram. Like attributes, the operations of a class are displayed in a list format, with each operation on its own line. Operations are documented using following syntax:
name(parameter list): type of return valueAccess Modifier
You can also apply access modifiers such as public access, protected access, private access, and package access applied to methods and attributes of a class, if required. These access modifiers determine the scope of visibility of the attributes and methods of a class. The notations used for indicating visibility are as shown in figure 5.3.
You can also add documentation information to a class. Notes and constraints can be added to a list of attributes. Notes contain additional information for reference while developing the system, whereas constraints are business rules that the class must follow, and are text included in curly brackets.
During the early phase of the system design conception, classes called Analysis classes are created. Analysis classes are of the following types as per their behavior:
Boundary Class: In an ideal multi tier system, the user interacts with system only with the classes called boundary class. For example, JSPs in a a typical MVC architecture form a boundary class.
Control Class: These classes typically don't contain any business functionality. However, their main task is to transfer control to the appropriate business logic class, depending on the inputs received from the boundary classes.
Entity Class: These classes are those that contain the business functionality. Any interactions with back-end systems are generally done through these classes.
Figure 5.5 Representation of Analysis Classes
Figure 5.6 A package