Some situations. You may want you to change a certain individual. But make the individuals of the entire system to be induced
And make a correct judgment. This situation is very common. Like. When you upgrade your main system chip. Your overall performance is also
Get corresponding improvements. (Don't necessarily. I just play a bit). So very obvious, your other components have also induced the main system
The performance of the system is changed. That is to say. The main system passes the subsystem that is not associated with it. I am upgraded now. You will get more
The improvement of many auxiliary performance is reached, and the success of the local scope will drive the overall superiority. So how can I achieve it?
What is this purpose? Obviously, a heart solution must be proposed. The meaning of Composite combination is also a combination of individuals.
Body, and uniform control. The following question is how to contact individuals. The most easily understood program is the number. Can be used to traverse all
Related objects. This customer simply calls an object. Don't consider other objects related to this object. And
When the customer adds a new object. The whole can also understand the problem that happens part.
Remember the electric robot playing when I was young? Upgrade the motor, join the new weapon. This can improve the overall performance of the robot.
OK we come to simulate robots in this environment
// Local Abstract Class Component {Protected Int Power; PUBLIC Component (String Name) {PartName = Name;}}
// Overall (overall also can be part of some other overall, and must be derived from component) to write abstract classes is intended to extend Abstract Class Macrocity: Component {protected int item; // Used to store the actual partial object protected arraylist macrotree = New macrotree (); public macrocity (String name) {base (name);
Protected Void Add (Component CT) {Macrotree.Add (CT);
Protected Void Remove (Component CT) {while (Componet CN = Next ()) {if (ct.partname == cn.partName) Macrotree.Remove (CT);}}
Protected component next () {item = macrotree.count-1; if (item> 0) Return Macrotree (item); else return null;}
Protected void change () {while (Componet CN = next () {this.power = cn.power;}}}
/ / Implement local public class handpart: Componet {public handpart () {base ("hand"); this.power = 200;}}
Public class feetpart: Componet {public feetpart () {base ("feet"); this.power = 400;}}
Public Class Bodypart: Componet {public body () {base ("body"); this.power = 800;}}
Public class headpart: Componet {public headpart () {base ("head"); this.power = 100;}} // overall implementation public class mymacro: macrocity {
}
// Customer assembly public class client {public static int main (String [] args) {mymacro mm = new mymacro ("mymacrocity"); handpart hap = new handpart (); Headpart Hep = new headpart (); feetPart fp = new Feetpart (); bodypart bp = new bodypart (); mm.add (HAP); mm.add (Hep); mm.add (bp); mm.changepow (); console.writeline "Overall performance:" mm.power); // hypothesis that the arm is attacked Power - 50 hap.power- = 50; console.writeLine ("Overall performance:" mm.power; // If the foot is completely damaged Mm.Remove (FP); console.writeline ("Overall performance:" mm.power);}}
This seems to be as shown in the overall situation as soon as the local change is immediately. This is the advantage of the Composite mode.