Re: Abstract classes and methods
Re: Abstract classes and methods
- Subject: Re: Abstract classes and methods
- From: Ondra Cada <email@hidden>
- Date: Wed, 29 Aug 2001 16:11:22 +0200
Chris,
>
>>>>> Chris Gehlker (CG) wrote at Wed, 29 Aug 2001 06:44:02 -0700:
CG> >That's not true: *if* you implement a virutal class, there is no need to
CG> >bother with init/dealloc of it. Actually, you can forget that also for
CG> >classes which are *not* abstract at all, but just happen to have no
CG> >"constructable/destructable" properties.
CG>
CG> Can you? What if you derive from it? How does its parent constr/destr get
CG> called when you construct/destruct a child class.
They would be inherited, of course. Where's the problem?
@interface OriginalClass ... @end
@implementation OriginalClass
-init { ....anything.... } /**/
// for dealloc the very same would apply
@end
@interface YourClass:OriginalClass ... @end
@implementation YourClass
// whatever there, it's no init nor dealloc
@end
@interface SomebodysClass:YourClass ... @end
@implementation SomebodysClass
-init {
[super init]; // the /**/ implementation called here, of course
...
}
@end
Should there be any number of intermediate classes, it would work as well:
say, you have an inheritance chain A:B:C:D:E:F:G:H:NSObject, none of B-H
implements dealloc. Then [super dealloc] in A would call the NSObject's
implementation.
We are in object-oriented environment, and so we have inheritance. It's that
simple.
Do forget the C++ constructor/desctructor nonsense; init/dealloc are quite
normal methods, in no way special (but by some conventions of using them).
Especially, they are inherited just like any other method is.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc