Describe the Purpose and Function of the Class Diagram
Purpose and Function of Class Diagram
The class diagram/object model is the cornerstone of object-oriented (OO) modeling.
The class diagram is the only OO model used to generate code and is the target for reverse engineering code into models.
The class diagram models classes, their component parts, and how they are related to one another. The class modeling elements include attributes, operations, stereotypes, properties, and associations. Associations may come in many variations, including simple, aggregation and generalization, qualified, and reflexive. Together these elements provide a rich set of tools for modeling software.
Blueprint and Static View of Elements
However, the class diagram is limited in what it can show us. Largely, it is a static view of the elements that make up the software. It is like a blueprint for a building or piece of machinery and you can see the parts used to make it and how they are assembled, but you cannot see how the parts will behave when they are set into motion.
This is why we need other diagrams to model behavior and interactions over time, modeling the objects in motion.
Although other models are necessary, remember that their purpose is to support the construction and testing of the class diagram. Whenever another diagram reveals new or modified information about a class or object,
the class diagram must be updated to include the new information.If this new information is not passed on to the class diagram, it will not be in your code.In the next lesson, you will learn how to describe attributes and operations for classes.
Classes used in Programming
Objects are the building blocks of an object-oriented software system. They model realworld collections of information (such as a purchase order) and are able to modify themselves. A class provides the blueprint for an object. For example, a library check-out system manages the movement of thousands of books, as patrons check them out and return them. Each book is represented by an object that maintains properties, such as the title, the author, and the ISBN. A class provides a blueprint for these objects. Throughout this chapter and the next, you will study short code examples written in Java and C++. The following Java code is the class definition of a book:
The same class is defined using C++ as follows:
The properties that form a class are its member variables. The Book class has three member variables: title, author, and ISBN.
Once a Book object is instantiated, values can be assigned to its member variables to define the unique characteristics of this book.
Both Java and C++ use dot notation to access member variables. The following Java code assigns values to the member variables
catcherInTheRye.title = "Catcher in the Rye";
catcherInTheRye.author = "J. D. Salinger";
catcherInTheRye.isbn = "0-316-76948-7";