Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1.  
  2. enum ALFABETY {
  3. Lacinka ,
  4. Greka,
  5. Cyrylica
  6. }
  7.  
  8.  
  9. abstract class Fabryka
  10. {
  11.  
  12. public abstract Alfabet stworzAlfabet();
  13.  
  14. public static Fabryka wybierzFabryke(ALFABETY wybor)
  15. {
  16. switch (wybor)
  17. {
  18. case ALFABETY.Lacinka:
  19. return new LacinkaFabryka();
  20. case ALFABETY.Greka:
  21. return new GrekaFabryka();
  22. case ALFABETY.Cyrylica:
  23. return new CyrylicaFabryka();
  24. default:
  25. throw new NotImplementedException();
  26. }
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34. class CyrylicaFabryka : Fabryka
  35. {
  36. public override Alfabet stworzAlfabet()
  37. {
  38. return new AlfabetRosyjski();
  39. }
  40. }
  41.  
  42. class GrekaFabryka : Fabryka
  43. {
  44. public override Alfabet stworzAlfabet()
  45. {
  46. return new AlfabetGrecki();
  47. }
  48. }
  49.  
  50. class LacinkaFabryka : Fabryka
  51. {
  52. public override Alfabet stworzAlfabet()
  53. {
  54. return new AlfabetLacinski();
  55. }
  56. }
  57.  
  58.  
  59. abstract class Alfabet
  60. {
  61. public abstract void wyswietl();
  62. public abstract string zwroc();
  63. }
  64.  
  65.  
  66. class AlfabetLacinski : Alfabet
  67. {
  68.  
  69. public override void wyswietl()
  70. {
  71. Console.WriteLine("abcde");
  72. }
  73. public override string zwroc()
  74. {
  75. return "abcde";
  76. }
  77.  
  78. }
  79. class AlfabetRosyjski : Alfabet
  80. {
  81.  
  82. public override void wyswietl()
  83. {
  84. Console.WriteLine("абвгд");
  85. }
  86. public override string zwroc()
  87. {
  88. return "абвгд";
  89. }
  90.  
  91. }
  92. class AlfabetGrecki : Alfabet
  93. {
  94.  
  95. public override void wyswietl()
  96. {
  97. Console.WriteLine("αβγδε");
  98. }
  99. public override string zwroc()
  100. {
  101. return "αβγδε";
  102. }
  103.  
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. public class Application
  112. {
  113. public static void Main(String[] args)
  114. {
  115. Console.OutputEncoding = Encoding.UTF8;
  116.  
  117. Fabryka fabryka = Fabryka.wybierzFabryke(ALFABETY.Lacinka);
  118. Alfabet alfabet = fabryka.stworzAlfabet();
  119. alfabet.wyswietl();
  120.  
  121. Fabryka fabryka1 = Fabryka.wybierzFabryke(ALFABETY.Greka);
  122. Alfabet alfabet1 = fabryka1.stworzAlfabet();
  123. alfabet1.wyswietl();
  124.  
  125. Fabryka fabryka2 = Fabryka.wybierzFabryke(ALFABETY.Cyrylica);
  126. Alfabet alfabet2 = fabryka2.stworzAlfabet();
  127. alfabet2.wyswietl();
  128.  
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement