• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Inherited constructors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Inherited constructors
      • From: Drew McCormack <email@hidden>
  • Prev by Date: Re: Class and methods for RadioButton
  • Next by Date: Re: Class and methods for RadioButton
  • Previous by thread: Re: Inherited constructors
  • Next by thread: Re: Inherited constructors
  • Index(es):
    • Date
    • Thread