Classification of Objects
Object-oriented programming views the real world as a collection of objects like airplanes, cars, and people. Some of these objects are similar. In other words, objects can be described in the same way if they use the same characteristics and exhibit the same behavior.
You can group all the characteristics and behaviors of these similar objects into one central class. This class is used to describe every object derived from it. Therefore, a class is a description of a number of objects that exhibit the same characteristics and the same behavior.
For example, the vehicle (make x, ..., model n), is an object of a class car. This object is a concrete instance of its class. Therefore, an object has an identity, a status (number of characteristic instances), and a behavior. The concepts of identity and status are different from one another.
Classes as Abstraction Forms
In a software context, abstractions are simplifications of complex relationships in the real world. You can abstract a real, existing object to the dimensions needed to simulate a certain section of the real world. In the figure, vehicles are used to explain the concept of abstraction. Software for a vehicle enthusiast and software for a scrap merchant contains different abstractions (classes) for objects. Therefore, depending on the type of abstraction, a class can contain different aspects of an object.
Comparing Classes and Objects
UML Representation of a Class
A class is represented by a rectangle in UML notation. A class can be represented as follows:
Attributes describe the data that can be stored in the objects of a class. They also determine the status of an object. Methods describe the functions an object can perform. They determine how an object behaves.
Example of a Class Diagram
A class diagram describes all static relationships between the classes. The basic forms of static relationships are as follows:
Association: A customer books a car at a rental car company.
Generalization and Specialization: A car, a bus, and a truck are all vehicles.
Note: Classes can also be shown in class diagrams with their attributes and methods. In this example of a class diagram, these attributes and methods have been omitted to improve clarity.
Association
An association describes a semantic relationship between classes. The specific relationship between objects in these classes is known as an object link. Therefore, object links indicate associations.
However, an association can also be recursive. In that case, the class would have a relationship with itself.
In most cases, recursive associations are used to link two different objects in the same class.
Each association has two roles, one for each direction of the association. Each role can be described by an association name. Each role has a cardinality that shows how many instances can participate in this relationship. The multiplicity is the number of participating objects in one class that have a relationship to an object in the other class. Like all other elements of the model, cardinalities are dependent on the concrete situation being modeled.
In this example, you could also require a cardinality of at least one to indicate that only someone who actually makes a booking becomes a customer of the rental car company. On the other hand, the cardinality of any number would allow for a more general definition of a customer.
Characteristics of the association are as follows: