My Blog List

Tuesday, October 19, 2010

Reviewing Concepts: Sussin' Out Time Portals



Program loaded.
run
[Switching to process 1280]
Running…
Portal Pilot: Engineering Log for Common Era 99.921 
TimePortal count is 1
TimePortal count is 2
....
 Portal Pilots has identified 2 new Time Portals in the Common Era

Debugger stopped.
Program exited with status value:0.



------------------
#import <stdio.h>
#import <Foundation/NSObject.h>


// Based on Page 110 ClassVariables2 and use of 'self'keyword

//  
// Portal Pilots are always searching for new Time Portals
//
// 
@interface TimePortal:NSObject
static int count;

+(int) getCount;
@end

//METHODS
@implementation TimePortal
-(TimePortal*) init

{
// (p 136) The 'super' keyword alows me to access the base class
// super = superclass = base class .... the class from which my
//     class TimePortal inherits or derives functionality
//     (p 119) This inheritance can include methods from the superclass
//  QUESTION I thought that a class could make use of ivars in the
//     super class too. But am not finding that this minute. CHECK BACK
// Here I'm using a constructor from the superclass to initialize the
//      data in an object when I create it (p 97)
//    Contructors are very typically called 'init'
//    The superclass for 'TimePortal' is 'NSObject'
self = [super init];
count++;
// A constructor returns a pointer to the object. 
// I get the pointer by calling the super class's init method. (p 97)
return self;
}

+(int) getCount
{
return count;
}
@end



int main (void) {
// Would LOVe to know how to display the SYSTEM DATE here
// It must be a keyword
// Look in the C++ Book
printf("Portal Pilot: Engineering Log for Common Era 99.921 \n");
    TimePortal *tp1 = [TimePortal new];
printf("TimePortal count is %i\n", [TimePortal getCount]);
TimePortal *tp2 = [TimePortal new];
printf("TimePortal count is %i\n", [TimePortal getCount]);
printf("\t....\n Portal Pilots has identified %i new Time Portals in the Common Era\n ", [TimePortal getCount]);

return 0;
}

No comments:

Post a Comment