1.2.1 Understanding Classes

A Class Describes a Kind of Object

So far, you have worked mainly with object instances:

Plain text
player1 : Player
team1 : Team

Those objects need a definition that tells the program what kind of information a Player or Team can contain.

That definition is a class.

At this stage, think of a class as the blueprint that describes a kind of object.

One Class Can Support Many Objects

Suppose the program has a Player class.

The program can create several Player objects:

C#
Player player1 = new Player();
Player player2 = new Player();
Player player3 = new Player();

All three are Player objects.

They can hold different state because they are different instances.

The class describes the common structure.

Objects Are Instances of Classes

This relationship can be summarized as:

Plain text
Player class
    ↓
creates/describes Player objects
    ↓
player1, player2, player3

The class is not Jordan, Casey, or Morgan.

Those are possible object states.

The class describes what a Player object can be like in the software.

Fields Belong to the Class Definition

A conceptual Player class might define fields such as:

Plain text
name
jerseyNumber
isAvailable

Every Player object created from that class can have its own values for those fields.

For example:

Plain text
player1.name = "Jordan"
player2.name = "Casey"

The field definition is shared by the type.

The field values belong to the individual objects.

A Class Is Source Code; an Object Is Runtime State

The class definition exists in source code.

An object created with:

C#
new Player()

exists while the program runs.

This distinction is useful:

Class
Defines structure.

Object
A particular runtime instance with current state.

UML Can Model the Class Separately from Its Objects

An object diagram might show:

Plain text
player1 : Player
-------------------------
name = "Jordan"

A class diagram can describe the Player type itself.

You will build that class-diagram notation in the next batch.

For now, focus on the conceptual difference:

A class describes the kind of object; an object is one specific instance.

Do Not Add Class Features You Have Not Learned Yet

Classes can eventually contain much more than fields.

Later activities introduce:

Those ideas are not required to understand the first class concept.

Start with the simplest useful mental model:

Plain text
class → defines what kind of object can exist
object → one instance created from that class