Think of a class as a blueprint for a kind of object.
A Player class might say that Player objects have:
Player
----------------
name
jerseyNumberThe class does not describe one particular player such as Jordan or Casey.
Instead, it describes the information that Player objects are expected to contain.
A class describes the general design.
An object represents one specific instance that follows that design.
Conceptually:
Both objects follow the same class structure.
Each object still has its own values and its own identity.
This distinction is important:
Class
For example:
Playerdescribes the general kind of thing.
But:
player1identifies one particular Player object.
A program does not need a completely different design for every player.
One Player class can describe the structure used by many Player objects:
The objects can contain different values even though they share the same structure.
This gives a program a consistent way to represent many things of the same kind.
Imagine a program that represents several soccer players.
Without a shared design, it would be easy for the program to represent similar objects inconsistently.
A class gives those objects a common structure.
Conceptually:
Player class
----------------
name
jerseyNumber
isAvailableEach Player object can then have its own values for those same pieces of information.
This makes the relationship between the model and the objects easier to understand.
When you look at a class, focus first on questions such as:
Do not start by asking what value one particular object has.
That question belongs to an object instance.
The class is about the shared design.
A class-level view might be:
Player
----------------
name
jerseyNumberAn object-level view might be:
player1
----------------
name = "Jordan"
jerseyNumber = 7The first view tells you what Player objects are structured to contain.
The second view tells you the current state of one specific Player object.
Object-oriented programs often need to represent many related objects.
Classes provide a way to define the common structure those objects follow.
That lets you reason about the design at two levels:
This distinction becomes especially important as programs contain more objects and more relationships between them.
The next pages show how classes are represented in UML class diagrams and how fields appear inside those diagrams.
Later in the module, you will connect that model to C# by defining classes and fields in source code.
For now, keep one idea clear: