Re: Inherited constructors
Re: Inherited constructors
- Subject: Re: Inherited constructors
- From: Ondra Cada <email@hidden>
- Date: Thu, 30 Aug 2001 00:16:06 +0200
drewmccormack,
>
>>>>> email@hidden (d) wrote at Wed, 29 Aug 2001 20:43:28 +0200:
d> But inheriting all constructors can be a pain in the neck. If you want
d> to ensure your objects are always in a valid state by only providing a
d> specialized constructor, you have a problem when you are also inheriting
d> 'init' for example. Say I want a class that stores an integer between 0
d> and 10. I do this by enforcing the constraint in a constructor
d> 'initWithIntValue:', and do not provide a public 'setter' such that the
d> class is immutable. But... wait... I've inherited bloody 'init', and
d> that doesn't enforce my constraint. I am forced to override it, and any
d> other constructors, when all that is really necessary is a single
d> constructor.
You failed to grok the "designated initializer" thing.
d> No, in general I find Obj-C extremely elegant and powerful, but I think
d> it would be better if constructors were not inherited.
I am quite afraid you are wrong in that.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc