A class is a template for creating objects. This is a fundamental concept, as it is a means for instantiating objects. Classes have parts to them that are known as fields and methods.
Objects, when they are created, are referred to as an instance of a class. So objects on the whole can be defined as instances of classes.
Classes in UML contain the name of the class (Button in the above image), The fields or data of the class, and the functionality or behavior of the class (methods).
Classes can be composed of other classes, commonly known as a has-a relationship. One class can “have” another class. A Car can be composed of an Engine, therefore a Car has an Engine.
Why is object-oriented programming structured around the use of classes?
PCA, B, and C will focus much on the first point of these three, using classes and developing with them. OOPA/B/C will be focused much on the second point and OODesign will be focused much on the third.
In the Parcheesi game, in a game with four players you will have 16 pawns. If the concept of Parcheesi was in a C# program you would have 16 pawn objects. The idea of abstraction - that an object in memory is an abstraction of a real-world thing, is a pervasive concept in computer science.
Abstraction is the process of separating ideas from specific instances of those ideas at work.
The specific instances in the above definition is referring to how we would compare objects in our programs to their real-world counterparts.
If, in my program I had an object of a Parcheesi token versus the real-world Parcheesi token, the former would be an idea of a token, compared to the real one.
The Parcheesi pawns in memory would look something like this. 16 different objects. There are 16 pawns in memory being represented abstractly. Remember that while there are 16 pawn objects, there is only one pawn class that the objects are derived from. The class can be seen as an abstraction of all 16 of the pawn objects.
Perhaps most directly, pawn objects are 16 instances of the ParcheesiPawn class.
Grady Booch, one of the original founders of UML, has his own definition of a class, and it is as follows: “A class is a set of objects that share a common structure and a behavior. A single object is simply an instance of a class.”