Classes

The classes used in the Cricket Score Tracker app are then created in the Classes folder. Here you will see a Batsman class and an AllRounder class. For the sake of simplicity, I only created these two classes. In cricket, all bowlers must bat, but not all batsmen have to bowl. You then get bowlers who can bowl and bat equally well, and they are defined as all-rounders. This is what I have modeled here.

Let's have a look at the Batsman class first. We want a batsman to have the abstract properties of a player, but he must also be a batter. Our class, therefore, inherits the Player base class (remember, we can only inherit from a single class) and implements the properties of the IBatter interface:

The class definition, therefore, ...

Get C# 7 and .NET Core 2.0 Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.