Why don't you do new? If you want to ask me this question. I think I have to answer, otherwise you must think that this is excessive. Ok, I will answer. First of all, I want to say where you have new, you have no doubt. When constructing the object. Good answer. Listening, if the structure is not a normal object but is quite complex object. May be necessary to read data from the database or other additional problems? Do you want to write them into a constructor? Can only be like that? Oh. . . Listening to this. I have to say. You violate object-oriented packages and factions. If you want to change this structure, do you consider the problem? What should we do if we don't have new? OK. . . Now I still answer. I think something I want to say may you have heard it. Anyway, I also send some boring things. Yes, you guessed. Factory (Factory) is done by it. We only use it to ask it. Then it is responsible for constructing the object. Do you want to listen to it? Needless to say. The shortcomings of the above NEW are basically its benefits. One more thing. It is no way to NEW. That is the interface. The factory returns the interface, that is, the factory can produce all the subclasses of such workpieces. It can be seen that standing on a very abstract link to complete the task. Public class myfactory {public static iMyclass Creator (String ClassName) {// loaded with a dynamic class. The function returned is the parent class interface iMyclass Swich (CASSNAME) {CASE: "Myclassa" return new myclassa (); case: "myclassb" return new myclassb ();}} If the factory itself does also interface mean? Is the higher level abstraction? Yes. Benefits? Abstract is not easy to make mistakes. Namespace factorymethod {using system;
Class myclass {. . . . . . . Read Some Data from Database or Other
}
Abstract class myfactory {protected myclass mc; abstract public void createclass ();
Public void constructObjects () {// CREATE Objects //..
// incruding class createclass ();}}
Class myrealfactory: myfactory {Override public void createclass () {mc = new myclass ();
}
Class MyRealclass: myclass {
}
Public class myclient {public static int main (string [] args) {myfactory mf = new myrealfactory ();
Mf.constructObjects (); return 0;}}}
OK is over. Just writing. Not good, there are still a lot of ominous places. There is a lot of places that have not been clear. Time rush is very sorry. Next continued. . . . . .