Directory
- I have seen
- Structural block diagram
- Code instance
- Summarize
Back to the top of what I see back to the top structure block diagram
Back to top code instance
Interface mcdonald{void cooking ();} Class Hamburger implements mcdonald{@Overridepublic void cooking () {System.out.println ("@-------mm Eat hamburger [email Protected] ");}} Class Cola implements mcdonald{@Overridepublic void cooking () {System.out.println ("@-------mm drink Cola [email Protected] ");}} Class Frenchfries implements mcdonald{@Overridepublic void cooking () {System.out.println ("@-------mm eat French fries [email Protected] ");}} public class Factory {public Mcdonald Getfood (String type) {if (type==null) {return null;} if (Type.equals ("Hamburger")) {return new Hamburger ();} else if (type.equals ("Cola")) {return new Cola ();} else if (type.equals ("Frenchfries")) {return new frenchfries ();} return null;} public static void Main (string[] args) {Factory Factory = new Factory (); System.out.println ("@-------mm want to eat hamburger [email protected]"); Mcdonald m1 = Factory.getfood ("Hamburger"); m1.cooking (); System.out.println ("@-------mm want to drink cola [email protected]"); Mcdonald m2 =factory.getfood ("Cola"); m2.cooking (); System.out.println ("@-------mm want to eat French fries [email protected] "); Mcdonald m3 = Factory.getfood ("frenchfries"); m3.cooking ();}}
Results
@-------mm want to eat hamburger [email protected]@-------mm eat hamburger [email protected]@-------mm want to drink cola [email protected]@-------mm drink cola [email protected]@-------mm want to eat French fries [email protected]@-------mm eat french fries [email protected]
Back to top of the summary
Factory mode of "design mode"