Information Technology Reference
In-Depth Information
Programs and Classes: A Quick Example
A running C# program is a group of interacting type objects, most of which are instances of
classes. For example, suppose you have a program simulating a poker game. When it is run-
ning, it has an instance of a class called
Dealer
, whose job it is to run the game, and several
instances of a class called
Player
, which represent the players of the game.
The
Dealer
object stores such information as the current state of the card deck and the
number of players. Its actions include shuffling the deck and dealing the cards.
The
Player
class is very different. It stores such information as the player's name and the
amount of money left to bet, and performs such actions as analyzing the player's current hand
and placing bets. The running program is illustrated in Figure 4-1.
Figure 4-1.
The objects in a running program
A real program would undoubtedly contain dozens of other classes besides
Dealer
and
Player
. These would include classes such as
Card
and
Deck
. Each class models some
thing
that
is a component of the poker game.
■
Note
A running program is a set of objects interacting with each other.