Inherited constructors
Inherited constructors
- Subject: Inherited constructors
- From: email@hidden
- Date: Wed, 29 Aug 2001 20:43:28 +0200
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
I must say, I think this is a weakness of obj-C.
I don't think the abstract class issue is very important, since an
abstract class is abstract because it has methods for which no
implementation can be provided. This can be achieved with a protocol, or
by simply leaving out the implementation in question, in which case an
exception will be thrown at runtime as soon as someone instantiates the
class and calls the unimplemented method.
But inheriting all constructors can be a pain in the neck. If you want
to ensure your objects are always in a valid state by only providing a
specialized constructor, you have a problem when you are also inheriting
'init' for example. Say I want a class that stores an integer between 0
and 10. I do this by enforcing the constraint in a constructor
'initWithIntValue:', and do not provide a public 'setter' such that the
class is immutable. But... wait... I've inherited bloody 'init', and
that doesn't enforce my constraint. I am forced to override it, and any
other constructors, when all that is really necessary is a single
constructor.
No, in general I find Obj-C extremely elegant and powerful, but I think
it would be better if constructors were not inherited.
Drew McCormack