On Friday, 13 July 2012 at 20:04:43 UTC, Gor Gyolchanyan wrote:
On Fri, Jul 13, 2012 at 11:59 PM, Era Scarecrow
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 {
  }
}


The seed itself must have private state, or else it would violate encapsulation and require nasty mixins.
And as I said, fruit can't know about apple.

Fruit doesn't know about apples in this last case, only that an apple IS a fruit (And can do anything a fruit can do). And the seed CAN have a private state, only part of the interface (from interface Seed) is exposed. So I do not see a problem.

 interface Seed {
   void func();
 }

 class Appleseed : Seed {
  int x; //private state
  void func() {x++;}
 }

 Appleseed a = new Appleseed();
 Seed s = cast(Seed) a;

 //appleseed
 a.func();
 a.x = 5;

 //seed
 s.func(); //known and callable
s.x = 10; //error, x isn't defined or known in seed. How is this not private state?

Reply via email to