SHARE
TWEET

Фабричный метод (Ractory Menthod)

yakovmonarh Aug 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class Program
  4. {
  5.    static void Main(string[] args)
  6.    {
  7.         Developer dev = new PanelDeveloper("000 КирпичСтрой");
  8.         House house1 = dev.Create();
  9.        
  10.         dev = new WoodDeveloper("Частный застройщик");
  11.         House house2 = dev.Create();
  12.        
  13.         Console.ReadLine();
  14.    }
  15. }
  16.  
  17. abstract class Developer
  18. {
  19.     public string Name {get;set;}
  20.    
  21.     public Developer(string n)
  22.     {
  23.         this.Name = n;
  24.     }
  25.    
  26.     abstract public House Create();
  27. }
  28.  
  29. class PanelDeveloper: Developer
  30. {
  31.     public PanelDeveloper(string n): base(n){}
  32.    
  33.     public override House Create()
  34.     {
  35.         return new PanelHouse();
  36.     }
  37. }
  38.  
  39. class WoodDeveloper: Developer
  40. {
  41.     public WoodDeveloper(string n): base(n){}
  42.    
  43.     public override House Create()
  44.     {
  45.         return new WoodHouse();
  46.     }
  47. }
  48.  
  49. abstract class House{}
  50.  
  51. class PanelHouse: House
  52. {
  53.     public PanelHouse()
  54.     {
  55.         Console.WriteLine("Панельный дом построен");
  56.     }
  57. }
  58.  
  59. class WoodHouse: House
  60. {
  61.     public WoodHouse()
  62.     {
  63.         Console.WriteLine("Деревянный дом построен");
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top