I’m new in objective-C and i wonder if its correct:
I have a class
@interface BaseClass : NSObject
And then i created object of that class:
BaseClass *baseClassObject = [[BaseClass alloc] initWith...];
After that i have another class:
@interface AdvancedClass : BaseClass
Depends on what data i’m getting in BaseClass (object initializer, methods later) i may want to expand functionality of object. So i want to baseClassObject become object from AdvancedClass class.
1) Is this correct?
2) Is this possible to “promote” object like that?
It’s possible and correct — that’s called polymorphism and it’s one of the major principles of object-oriented programming. You simply create instances of the base class or the subclass in your methods depending on what kind of functionality you need.