Trying to understand



Im trying to understand this:

// Create an instance of BNREmployee
BNREmployee *mikey = [[BNREmployee alloc]init];

    // Give the instance variable interesting values using setters
    // [mikey setWeightInKilos:80];
    // [mikey setHeightInMeters:1.85];
    mikey.employeeID = 12;
    mikey.hireDate = [NSDate dateWithNaturalLanguageString:@"Aug 2nd, 2010"];[/code]

Does this mean you implicitly create a BNRPerson instance by setting the BNRPerson variables weight and height via the created instance of BNREmployee or do you simply extend the created instance of BNREmployee with these two extra variables ?


It is crucial to understand that a BNREmployee object is also a Person object, because of inheritance.


BNREmployee *mikey = [[BNREmployee alloc]init];

creates a blank BNREmployee object which is also a blank person object (thanks to inheritance.)

By setting the values of the properties your are not (implicitly) creating the object, but you are modifying the existing object. (Maybe you meant to say configure or modify.)


I think my last remark on ‘extending (modifying) the Person object’ (rather then implicitly creating a Person object) is basically what you are saying.


BNREmployee is a BNRPerson and as such has all the same characteristics but some extra characteristics.


for simplicity’s sake, you can also write like this

is the same as