Why should I create a superclass property just to use a subclass

I am following an online course at Stanford. IOS 7 app development for iPhone and iPad ( link to the course in itunes U ).

The first task asks students to create several classes (Card, PlayingCard, Deck, PlayingCardDeck), described in detail in the notes, and update the view controller to display a random card in the deck of playing cards.

Two of the required tasks:

  • Add a private property of type Deck * to CardGameViewController.
  • Use a lazy instance to highlight and initialize this property (in getter) so that it starts with the full PlayingCards deck.

I added the following to my code:

// CardGameViewController.m
#import "PlayingCardDeck.H"

@interface CardGameViewController ()
...
@property (strong, nonatomic) Deck *deck;
@end

@implementation CardGameViewController
- (Deck *)deck
{
    if (!_deck) _deck = [[PlayingCardDeck alloc] init];
    return _deck;
}
...
@end

The hint indicates the following:

  • , , , Deck (not PlayingCardDeck), , , PlayingCardDeck. - , PlayingCardDeck , , , "". - , .

PlayingCardDeck Deck. , "".

, Deck PlyaingCardDeck.

+4
1

Deck, CardGameViewController . , , .

, , CardGameViewController , PlayingCardDeckGameViewController TarotCardDeckGameViewController PinochleCardDeckGameViewController ..

Deck PlayingCardDeck CardGameViewController.

+1

All Articles