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 14:55:32 +0200
Bradley,
incidentally, wouldn't is be better to place your answer _under_ the quoted
text? It's a bit inconvenient to edit the complete message each time so as
the thread can be read smoothly...
SB> >If you describe a situation which would be impossible or at
SB> >least quite
SB> >inconvenient to solve without abstract classes -- I am not
SB> >aware of any such
SB> >-- I'll do my best to answer.
>
>>>>> Smith, Bradley (SB) wrote at Wed, 29 Aug 2001 13:11:24 +0100:
SB> Okay, classic OO example. I have an abstract class called Shape.
SB> Shape is meaningless on its own
Is it? Let's say, is NSView really meaningless on its own? Would it be
sensible to prevent its instantiation?
SB> but if you subclass it e.g. Square,
SB> Circle etc. then those classes can be used.
Right. Very common case. But where comes the useability of the abstractness from?
Either the Shape class would have no -initWith... and +shapeWith...methods;
if so, nobody would try to instantiate it directly anyway. Or it might have a
number of -initWith... and +shapeWith... methods which actually return
subclasses, and we are speaking class clusters.
SB> What you don't want to do is
SB> let anyone using your classes instantiate an instance of class Shape
SB> directly.
Why would I do that? If somebody feels he *does* need to do some "Shape
*s=[[[Shape alloc] init] autorelease]" to use it, let's say, as a generic
shape placeholder in some container or whatever alike, why would I prevent
it?
Don't please speak to me of preventing errors: one can unintentionally do a
plenty of nasty things, but trying a [[[Shape alloc] init] autorelease]
instead of [Shape circleWithRadius:r centre:pt] (or even [Circle
circleWithRadius:r centre:pt] if we don't speak clusters) very definitely
does not look as one of them...
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc