nested class inheritance
Gor Gyolchanyan
gor.f.gyolchanyan at gmail.com
Fri Jul 13 12:35:24 PDT 2012
On Fri, Jul 13, 2012 at 11:26 PM, Era Scarecrow <rtcvb32 at yahoo.com> wrote:
> On Friday, 13 July 2012 at 19:08:54 UTC, Gor Gyolchanyan wrote:
>
> If you make seed static, then Appleseed & apple will have access to Fruit
>>> but seed (by itself) won't. Other combinations faile as far as I can tell.
>>> How far you can take inner class inheritance I don't know, but it seems not
>>> that many levels.
>>>
>>
>> This all won't work, because having Fruit know about Apple defeats the
>> whole purpose.
>>
>
> So why not...??
>
> class Seed{} //same as static class in fruit
>
>
> class Apple {
> class Appleseed : Seed {}
> }
>
> Perhaps you would rather have Seed as an interface instead? It seems like
> I need a full detail of how everything connects together, so let's see..
>
> Fruit covers apple (but maybe not seed)
> Apple covers (and is a class of) fruit, but also contains a seed (or the
> seed pertains to Apple specifically)
> All fruits (including apple's) have seeds that do specific things, namely
> plant, water and grow, and perhaps produceFruit.
>
> If that isn't right, explain how the relationship of it all goes and a
> possible solution may show itself.
>
The seed can't be an interface because it needs to contain state. For
instance the progress towards becoming the respective fruit.
The seed needs to be aware of the fruit it came from to access the fruit's
DNA to inherit the traits of that fruit when it grows into a fruit of its
own. (Please note, that it's just an example).
A fruit can have multiple such seeds, each of which must have it's own
state and connection to the same fruit they came from.
So, we start off by inheriting from Fruit, defining the properties of that
fruit (It's an Apple, it's delicious and it goes great in a pie). Then we
define several different types of Apple seeds, each of which need access to
the apple.
--
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120713/3771137d/attachment.html>
More information about the Digitalmars-d
mailing list