My Composite In C #

xiaoxiao2021-03-06  120

// mycompositeusing system; using system.collections;

// ---------------------------------- Class FileEleMentabstract Class CfideElelement {// Fields protected since; public cfileElelement String name) {this.name = name;}

Public Abstract Void Add (CFILEEELEment E); Public Abstract Void Remove (CFILEEELEMENT E); Public Abstract Void Display ();

// class cfileclass 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 (CFILEEELEMENT E) {Console.writeline ("Can't Remove Any Sub Files!");} public override void display () {console.writeline (this.name);

// Class Cfolderclass 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

// testappclass testapp {public static void main (string [] args) {cfolder root = new cfolder ("z: /"); cfolder Afolder = New CFolder ("Games /"); Afolder.Add (New CFile ("CSTRIKE ")); root.add (Afolder); root.display (); while (true);}};

转载请注明原文地址:https://www.9cbs.com/read-126603.html

New Post(0)