My Blog List

Tuesday, November 16, 2010

Time Travel Protocols


Loading program into debugger…
Program loaded.
run
[Switching to process 30368]
Running…
Encountered a Time Portal, type Creek
Encountered a Time Portal, type Alley

Debugger stopped.
Program exited with status value:0.

//
//  TimeTravelProtocol.m

//  Based on page 161 Holzner Quick Start Book

//  Created by xxxxx on 11/11/10.
//  Copyright 2010 __xxx__. All rights reserved.
//

// page 155 The Point of using Protocols
// Protocols let me specifiy a method or methods that can be used in multiple classes.
//   Protocols let me declare methods and to define the implementation in the class
//        Protocols let me make sure
//    that all my derived classes implement the same methods - though the implementation may be different

// In this project I create a 'printing' protocol, which I can include in the interface files of other classes
//     it ADDS 'print' to their interfaces
//  I can implement the print method a different way for each class


// NOTE IMPORTANT: IN PREVIOUS EXAMPLES I would have included the
//          (void) print;
//   in the .h files associated with each class alley.h and creek.h) - but now this is only in printing. h
//  So I can be sure that my derived classes will inherit this method from their base classes

// Apparently this is how Objective-C fakes out multiple inheritance too - but I don't know exactly how to make that
//   happen yet from multiple parents at the same level....


// Another way  this book does something like this, is with prototypes
//     that is BEFORE it moved onto object-oriented methods
//   and is back on page 63 'a function prototype is also called a function declaration,
//       as opposed to a definition, which includes the body of the function


#import <stdio.h>
#import "Creek.h";
#import "Alley.h";

int main(void) {
   
    Creek *c = [Creek new];
    [c print];
   
    Alley *c2 = [Alley new];
    [c2 print];
   
    return 0;
}

No comments:

Post a Comment