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.
Attribute Compartment
The attribute compartment simply lists the attributes of the class using the notation you learned previously.
The list order does not matter.
Operation compartment
Likewise, operations are listed in the operation compartment using the notation you learned in the first course in this series.
The completed class definition can be shown either as the entire class definition with all three compartments visible or as
just the name compartment.
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).
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;
};