Re: Abstract classes and methods
Re: Abstract classes and methods
- Subject: Re: Abstract classes and methods
- From: Chris Gehlker <email@hidden>
- Date: Wed, 29 Aug 2001 10:15:58 -0700
On 8/29/01 7:21 AM, "Smith, Bradley" <email@hidden> wrote:
>
Let's not turn this into a "my language is better than your language"
>
slanging match. C++ has served me - and others no doubt - well over the
>
years. At the moment Obj-C looks a little bizarre but that's probably
>
because it's new to me.
I'm really not trying to get into a slanging match here. It's just that
this stuff is complicated enough without being very precise about
terminology.
>
IIRC the original question was (basically) how to create the equivilent of
>
an abstract C++ class in Obj-C wasn't it? All the replies have been along
>
the lines "why do you want to do that?", "that's a stupid idea" etc. If
>
Obj-C can't do it then just tell us. We don't want excuses. We all know by
>
now why Stuart wants an abstract class so let's set about helping him. I
>
also would like to know how to do it.
This may be messages passing in the night stuff but I did learn how to do
it from the discussion and it was very useful. Basically, you use a class
cluster. You define a bunch of init methods that only return concrete
classes. So you can do:
Shape *shape1 = [[Shape alloc] initWithCircleWithCenter:thePoint radius:5;
Shape *shape2 = [[Shape alloc] initWithRectangeOfWidth:8.3 heigth:10.2
corner:thePont;
Shape *shape3 = [[Shape alloc] initWithOvalOfFocus1:point1 focus2:point2;
Etc. etc.
To make shape virtual, you carefully don't define a simple init method for
it. To make it abstract non-virtual you go ahead and define the simple init
method.
The old ObjC hands will tell you that ObjC is a simple extension to C but
they lie. ObjC is full of conventions that aren't enforced by the compiler,
extra-linguistic conventions?, but that "everybody knows" and that are
really necessary to make the language useful. The complexity of ObjC + ObjC
extra-linguistic conventions approaches the complexity of C++ + C++
extra-linguistic conventions.
--
Heaven is under our feet as well as over our heads. -Henry David Thoreau,
naturalist and author (1817-1862)