nested class inheritance
Era Scarecrow
rtcvb32 at yahoo.com
Fri Jul 13 12:59:24 PDT 2012
On Friday, 13 July 2012 at 19:35:34 UTC, Gor Gyolchanyan wrote:
>
> The seed can't be an interface because it needs to contain
> state. For instance the progress towards becoming the
> respective fruit.
The interface itself may not have state, but what uses the
interface can have state. So i don't see an issue. Worse case you
can use an abstract class which is a partial definition.
interface Counter {
void addOne();
int getCount();
}
//A contains state and is both A and Counter.
class A : Counter {
int x;
void addOne() {x++;}
void getCount() {return x;}
}
> 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 far...
class Fruit {
class Seed {
class Apple {}
}
}
>
> 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.
Hmmm...
interface Seed {}
class Fruit {
class Appleseed : Seed {
class Apple {}
}
//or?
static class Apple {
class AppleSeed : Seed {} //multiple seeds, but need Fruit
access?
}
}
or perhaps...?
interface Seed{}
interface Fruit{}
//Apple knows it's a fruit..
class Apple : Fruit {
//Appleseed is from the Apple (which is a fruit as well)
//Appleseed is a seed, we can have multiple seeds from Apple,
all which know
//all about Apple's (and basic fruits) but not about non-appple
seeds.
class Appleseed : Seed {
}
}
More information about the Digitalmars-d
mailing list