Design Pattern 2-Factory

xiaoxiao2021-03-06  63

Using system;

Namespace pattern {///

/// Summary description for class1. /// public class factory {public factory () {} public static fruit name (int flag) {ix (flag == 1) Return new apple (); if (flag == 2) return new orange (); else return null;}

}

Public interface fruit {string grow (); string water ();

}

Public Sealed Class Apple: Fruit {Public Apple () {Return "this is apple result";} public string water () {return "this is apple water";}}

Public Sealed Class Orange: Fruit {public Orange () {} public string growth () {Return "this is orthol";} public string water () {return "this is oory water";}

}} // Simple Factory Mode Console.writeline (Factory.made (1) .grow ()); console.writeline (factory.made (2) .grow ());

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

New Post(0)