//mycomposite using system; using system.collections;
//----------------------------------class fileelement abstract class cfileelement { //fields protected string name;
public cfileelement(string name) { this.name=name; }
public abstract void add(cfileelement e); public abstract void remove(cfileelement e); public abstract void display(); };
//class cfile class cfile:cfileelement { public cfile(string name):base(name){}
public override void add(cfileelement e) { console.writeline("can't add any files under a file!"); } public override void remove(cfileelement e) { console.writeline("can't remove any sub files!"); } public override void display() { console.writeline(this.name); } };
//class cfolder class cfolder:cfileelement { private arraylist children =new arraylist();
public cfolder(string name):base(name){}
public override void add(cfileelement e) { children.add(e); } public override void remove(cfileelement e) { children.remove(e); } public override void display() { console.writeline(this.name); foreach(cfileelement e in children) { e.display(); } }
}; //----------------------------------class element
//testapp class testapp { public static void main(string[] args) { cfolder root = new cfolder("z:/"); cfolder afolder=new cfolder("games/");