how to change attribute in descendant?

%u u at infearof.spm
Thu Jan 18 16:52:19 PST 2007


novice2 Wrote:

> Then in some descendant i need "open" it.
This seems to be a clear sign of misunderstanding/misusing object orientation.
Descendendants, as you say, need to be like ancestors without any restrictions. Thus there cannot be any need to "open" any closed "attributes".

IMO you mean something like this:

class Animal{
  Attribute walk=null, kill=null;
  bool canWalk(){ return walk !is null;}
  bool canKill(){ return kill !is null;}
}
class Tiger:Animal{
  this(){ walk= new Walk(4);}
}
class Walk:Attribute{
  int legs;
  this( int count){ legs= count; };
}
class Attribute{}
void main(){
  Tiger t= new Tiger;
  writefln( t.walk.legs, t.canWalk, t.canKill);
...
  
  


More information about the Digitalmars-d-learn mailing list