Problem Analysis  «Prev  Next»
Lesson 6 Review class diagram notation review, part 1
ObjectiveReview the Class Diagram Notation

Review the Class Diagram Notation

Classes are modeled using
  1. a single rectangular shape with
  2. three internal compartments: name, attribute, and operation.

Name compartment

The name compartment holds 1) the class name, 2) an optional stereotype, and 3)optional properties. The name is located in the center of the compartment. The stereotype (<< >>) may be used to limit the role of the class in the model, and is placed at the top of the compartment. Common examples of class stereotypes include <<Factory>>, based on the Factory design pattern, and <<Interface>>, for Java interfaces or for user interfaces. Properties use the constraint notation and are placed in the bottom-right corner of the compartment. Properties are basically constraints, used to clarify intent in defining the model element. Properties can be used to document the status of a class under development or for designations such as abstract and concrete.

Name compartment
Name compartment

Attribute Compartment

The attribute compartment simply lists the attributes of the class using the notation you learned previously.
The list order does not matter.

Attribute compartment
Attribute compartment



Operation compartment

Likewise, operations are listed in the operation compartment using the notation you learned in the first course in this series.
Operation compartment
Operation compartment

The completed class definition can be shown either as the entire class definition with all three compartments visible or as just the name compartment.

complete-class
  1. Name compartment
  2. Attribute compartment
  3. Operation compartment
  4. Class name
  5. Properties
  6. Stereotype

The three parts of the class diagram notation are described below

Class Diagram and Notation

The sample program is very simple. It is a program to calculate and print a statement of a customer's charges at a video store. The program is told which movies a customer rented and for how long. It then calculates the charges, which depend on how long the movie is rented, and identifies the type movie. There are three kinds of movies: regular, children's, and new releases. In addition to calculating charges, the statement also computes frequent renter points, which vary depending on whether the film is a new release.

Several classes represent various video elements. Here's a class diagram to show them (Figure 2.6).
Class diagram of the starting-point classes
Figure 2.6: Class diagram of the starting-point classes. Only the most important features are shown. The notation is Unified Modeling Language UML

I will show the code for each of these classes in turn.
Movie: Movie is just a simple data class.
public class Movie {
public static final int CHILDRENS = 2;
public static final int REGULAR = 0;
public static final int NEW_RELEASE = 1;
private String _title;
private int _priceCode;
public Movie(String title, int priceCode) {
_title = title;
_priceCode = priceCode;
}
public int getPriceCode() {
return _priceCode;
}
public void setPriceCode(int arg) {
_priceCode = arg;
}
public String getTitle (){
return _title;
};
}

Rental: The rental class represents a customer renting a movie.
class Rental {
private Movie _movie;
private int _daysRented;
public Rental(Movie movie, int daysRented) {
_movie = movie;
_daysRented = daysRented;
}
public int getDaysRented() {
return _daysRented;
}
public Movie getMovie() {
return _movie;
}
}

Customer: The customer class represents the customer of the store. Like the other classes it has data and accessors:
class Customer {
private String _name;
private Vector _rentals = new Vector();
public Customer (String name){
_name = name;
};
public void addRental(Rental arg) {
_rentals.addElement(arg);
}
public String getName (){
return _name;
};

Complete Class with Three Compartments

1) First compartment is the name of the class 2) Second compartment are the attributes of the class which will be translated into data members 3) The third part of the class are the accessors and mutators, also known as getters and setters
Completed class definition
  1. First compartment is the name of the class
  2. Second compartment are the attributes of the class which will be translated into data members
  3. The third part of the class are the accessors and mutators, also known as getters and setters


  1. Name compartment
  2. Attribute compartment
  3. Operation compartment
  4. Class name
  5. Properties
  6. Stereotype