Class Diagrams

A class diagram describes the static structure of the system, and provides the domain view of the real-world entities. It consists of classes, their structure, and their relationships to other classes. The following sections describe the notation of a class and the type of relationships that can exist between classes.

Class Notation

A class represents both the properties (attributes) and the behavior (operations) of a domain entity. In UML, a class is modeled as a solid rectangle with three compartments. The top compartment holds the class name and other general properties of the class. The middle compartment holds a list of attributes. The bottom compartment holds a list of operations.

For example, Figure D.1 shows the EnrollmentCartEJB class. It consists of the attributes ctx (of type SessionContext) and cart (of type HashSet). The class also contains the operations addCourses and getCourses. The parameters and return type can be shown for operations. For example, the method addCourses accepts the input parameter courseIds and returns void.

Figure D.1. Class example.


The attribute and operation compartments can be suppressed to reduce detail in an overview.

Stereotype Notation

A stereotype is an extension of the vocabulary of the UML that enables you to create a new kind of building block. It represents the subclassification of a model element.

A stereotype is shown in angle brackets (<<name>>). For example, an interface is displayed by using class notation with the stereotype <<interface>>. Figure D.2 shows SessionBean is an interface.

Figure D.2. Stereotype example.


Generalization/Inheritance Relationship Notation

A generalization relationship between classes shows that the subclass shares the structure or behavior defined in superclasses. A generalization relationship is drawn as a solid line with an arrowhead pointing to the superclass. For example, Figure D.3 shows that EnrollmentCart inherits from EJBObject.

Figure D.3. Generalization relationship example.


Association Relationship Notation

An association represents a semantic connection between two classes. Associations are bidirectional. Figure D.4 shows the association between the Person and Company classes.

Figure D.4. Association relationship example.


The association name describes the nature of the relationship. You can also show the direction in which to read the name. Figure D.4 shows the name of the association is works for and also shows the direction in which to read the association.

Association roles describe the “faces” that classes present to each other within an association. Figure D.4 shows the role of the Person is employee and the role of the Company is employer for this association.

Multiplicity indicates how many instances of one class may be associated with a single instance of another class. Multiplicity values are specified in the format lower-bound..upper-bound. An unlimited multiplicity value is denoted by an *. Figure D.4 shows that a Person is employed by one Company; a Company employs one or more Persons.

Aggregation/Composition Relationship Notation

An aggregation relationship is used to show a whole or partial relationship within which one class represents a larger thing that consists of smaller things.

An aggregation relationship is shown as a solid line with a diamond at one end. The diamond end designates the whole thing.

Composition is a special form of aggregation within which the parts are inseparable from the whole. The lifetime of the part is coincident with the lifetime of the whole. A composition relationship is shown as a solid line with a filled diamond at one end.

For example, Figure D.5 shows that OrderEJB is composed of many LineItemEJBs, and that the name of the composition relationship is Order-LineItem.

Figure D.5. Composition relationship example.


Realization Relationship Notation

A realization is a relationship between an interface and the class that provides the interface's services. A realized interface is represented by a dashed line with an arrowhead pointing to the interface.

Figure D.6 shows that the class EnrollmentCartEJB implements the interface SessionBean.

Figure D.6. Realization relationship example.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.247.53