|
|
The Die Class | We start with an example: The class Die.
This example illustrates many basic ideas behind classes and objects. |
To be concrete we start by looking at a complete class written in C# |
The class Die encapsulates a couple of variables (numberOfEyes and randomNumberSupplier).
It also implements a number of methods that allow us to use a die. The most important
operation is Toss. |
A program that constructs and tosses a number of dies. |
What is printed when we run the program shown above. |
This version of class Die is not limited to six sides. It can have an arbitrary
number of sides. |
|
The Die class is a template or blueprint from which we can create an arbitrary number of die objects |
Read more about class Die in the text book version of this material. |