User's Guide

Designing the objects

Designing the card part

For this example, the fundamental object in the lists is the Card object. A card, in the real world, has several attributes.

Each of these attributes will be implemented in the reusable Card part.

We will also need to consider some other attributes that help to properly represent the cards visually to the user.

The actions available for a card are quite limited.

Designing the card deck

There are various types of card decks. Many card games are played with a standard deck of playing cards. However, some card games, such as Pinochle use a specialized card deck. Regardless of the type of deck being used there are certain actions and attributes they have in common.

We will implement each of these attributes and actions in a card deck part that can be used in virtually any card game.

One key design point that needs to be addressed is whether the card deck should subclass the Ordered Collection part or contain an ordered collection of cards as an instance variable. The advantage of subclassing the Ordered Collection part is that its methods can be used to reduce the work involved in implementing the card deck. The advantage of using an instance variable is that internally the card deck can be implemented as something other than an ordered collection, perhaps as an array. It also provides that card deck with the opportunity to control what gets added to the ordered collection.

We will implement the card deck using an instance variable to contain the ordered collection of cards.

Designing the playing card deck

With the design of the card and card deck complete, the design of the playing card deck becomes relatively straightforward. The playing card deck reusable part will subclass the card deck class and initialize it to contain the standard 52 cards of four suits.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]