I think this is a better way for overriding methods?


#1

Okay so I re-read this chapter to get a little clarity. I think the better way to handle the overriding of our methods is this way:

ForeignStockHolding.m

#import "ForeignStockHolding.h"

@implementation ForeignStockHolding

@synthesize conversionRate; 

- (float) costInDollars
{
    float fcost = [super costInDollars];

    return fcost * conversionRate;
}

- (float) valueInDollars
{
    float fvalue = [super valueInDollars];

    return fvalue * conversionRate; 
}
@end

This way - we’re not typing in the original formula. We’re modifying it. So we use super to get the original formula from the super class (In this case, StockHoldings) and just multiply it by the conversion rate.

The joy I had when I realised this!! :smiley: (Geeky, right? )


#2

[quote=“Tander”]

The joy I had when I realised this!! :smiley: (Geeky, right? )[/quote]

Same here :laughing: