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
The given class diagram depicts a UML class representation with a single compartment that includes the class name and a stereotype.
Attributes of the Class Diagram:
  1. Class Name
    • The class is named "Customer" and is centered within the diagram.
  2. Stereotype
    • The class is marked with the stereotype <<User>>, indicating that this class represents a user-related entity in the system.
  3. Name Compartment
    • This diagram only includes the name compartment, which means it does not display attributes (variables) or operations (methods) within the class.
  4. Metadata Information
    • A timestamp (last updated 10-27-98) is included, suggesting that this class might be part of a version-controlled or historical system model.

Missing Elements (Expected in a Full Class Diagram)
  • Attributes Compartment: Typically contains class attributes (e.g., customerID, name, email).
  • Methods Compartment: Usually lists the operations or functions of the class (e.g., placeOrder(), updateProfile()).
  • Relationships: This diagram does not show associations, inheritance, or dependencies with other classes.

Interpretation
  • This is a simplified UML class representation focusing only on the identification of a user-related class (Customer).
  • It might be part of a use case model rather than a detailed class diagram, as it lacks attributes and behaviors.
Name compartment

List of Compartments

  • 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.


Additional Class Views

Many tools also support different views of the operations, for example, name, argument data types, and return data type only, or with fully expanded arguments.
Class without full signature
Attributes of the "Customer" Class Diagram This UML class diagram represents the Customer class and provides details about its attributes and methods. Below is a breakdown of its components:
1. Class Name & Stereotype
  • Class Name: Customer
  • Stereotype: <<User>>, indicating this class represents a user entity in the system.
  • Last Updated: 10-27-98, signifying a historical update timestamp.

2. Attributes (Instance Variables)
Attribute Data Type Default Value Visibility Description
name char "blank" Private (-) Stores the customer's name
mailingAddress Address null Private (-) Holds the customer's mailing address
/accountBalance Dollar 0 Derived (/) Represents the customer's account balance
customerid integer 0 Private (-) Unique identifier for the customer

Key Observations
  • Private Attributes (`-`):
    • name, mailingAddress, customerid, and accountBalance are all private, meaning they can only be accessed within the class.
  • Derived Attribute (`/accountBalance`):
    • The `/` symbol indicates that accountBalance is derived (calculated rather than stored).
  • Default Values:
    • name = "blank" (default character value)
    • mailingAddress = null (no address assigned initially)
    • /accountBalance = 0 (default monetary value)
    • customerid = 0 (default integer ID)

  • Private Attributes (`-`):
    • name, mailingAddress, customerid, and accountBalance are all private, meaning they can only be accessed within the class.
  • Derived Attribute (`/accountBalance`):
    • The `/` symbol indicates that accountBalance is derived (calculated rather than stored).
  • Default Values:
    • name = "blank" (default character value)
    • mailingAddress = null (no address assigned initially)
    • /accountBalance = 0 (default monetary value)
    • customerid = 0 (default integer ID)

3. Methods (Operations)
Method Return Type Visibility Description
+ getName() Not specified Public (+) Retrieves the customer's name
+ setName() Not specified Public (+) Updates the customer's name
+ setAccountBalance() Not specified Public (+) Modifies the customer's account balance
+ getAccountBalance() Not specified Public (+) Retrieves the customer's account balance
+ setAddress() Not specified Public (+) Updates the customer's mailing address

Key Observations
  • Public Methods (+): All methods are public, allowing external access.
  • Getter & Setter Methods
    • getName() / setName() for managing name.
    • getAccountBalance() / setAccountBalance() for managing accountBalance.
    • setAddress() for modifying mailingAddress.

Summary
This Customer class follows Object-Oriented Programming (OOP) principles:
  • Encapsulation: Private attributes with public getter/setter methods.
  • Derived Attributes: accountBalance is not stored directly but computed dynamically.
  • Default Values: Provides initial values for attributes.
1) Class without full signature

Elided or hidden class details
2) Elided or hidden class details

The UML supports user-defined compartments as well. You can define virtually any type of information to append to a class by creating additional compartments. At this time, I am unaware of any tools that allow you to take advantage of this feature.



Compartment Definition in Object Modeling

A graphical subdivision of a closed symbol, such as a class rectangle divided vertically into smaller rectangles. Each compartment shows properties of the element that it represents. Compartments come in three kinds: fixed, lists, and regions.
Notation:
A fixed compartment has a fixed format of graphical and text parts to represent a fixed set of properties. The format depends on the kind of element. An example is a class name compartment, which contains a
  1. stereotype symbol and/or name,
  2. a class name, and
  3. a property string
that shows various class properties. Depending on the element, some of the information may be suppressible.
A list compartment contains a list of strings that encode constituents of the element. An example is an attribute list, where the encoding depends on the constituent type. The list elements may be shown in their natural order within the model, or they may be sorted by one or more of their properties (in which case, the natural order will not be visible). For example, a list of attributes could be sorted first on visibility and then on name. List entries can be displayed or suppressed based on the properties of the model elements. An attribute compartment, for instance, might show only public attributes. Stereotypes and keywords may be applied to individual entries by prepending them to the list entry. A stereotype or keyword may be applied to all subsequent entries by inserting it as a list entry by itself. They affect all subsequent list entries until the end of the list or another such running declaration. The string <<constructor>> placed on a separate line in an operation list would stereotype the subsequent operations as constructors, but the string «query» further down the list would revoke the first declaration and replace it by the <<quer>> stereotype.
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

SEMrush Software