Struktura.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace _06_3_Dekorator_Interfejsy
  7. {
  8. public interface ISamochod
  9. {
  10. string PodajNazwe();
  11. double PodajCene();
  12. }
  13. public class Ford : ISamochod
  14. {
  15. public string PodajNazwe()
  16. {
  17. return "Ford";
  18. }
  19. public double PodajCene()
  20. {
  21. return 50000;
  22. }
  23. }
  24. public class Peugot : ISamochod
  25. {
  26. public string PodajNazwe()
  27. {
  28. return "Peugot";
  29. }
  30. public double PodajCene()
  31. {
  32. return 60000;
  33. }
  34. }
  35. public interface IDekorator : ISamochod
  36. {
  37. ISamochod pojazd { get; set; }
  38. }
  39. public class Klima : IDekorator
  40. {
  41. public ISamochod pojazd { get; set; }
  42. public Klima(ISamochod aPojazd)
  43. {
  44. pojazd = aPojazd;
  45. }
  46. public string PodajNazwe()
  47. {
  48. return pojazd.PodajNazwe() + " z klimatyzacją";
  49. }
  50. public double PodajCene()
  51. {
  52. return pojazd.PodajCene() + 7000;
  53. }
  54. }
  55. public class Metalik : IDekorator
  56. {
  57. public ISamochod pojazd { get; set; }
  58. public Metalik(ISamochod aPojazd)
  59. {
  60. pojazd = aPojazd;
  61. }
  62. public string PodajNazwe()
  63. {
  64. return pojazd.PodajNazwe() + " z lakierem metalic";
  65. }
  66. public double PodajCene()
  67. {
  68. return pojazd.PodajCene() + 2000;
  69. }
  70. }
  71. public class Zimowki : IDekorator
  72. {
  73. public ISamochod pojazd { get; set; }
  74. public Zimowki(ISamochod aPojazd)
  75. {
  76. pojazd = aPojazd;
  77. }
  78. public string PodajNazwe()
  79. {
  80. return pojazd.PodajNazwe() + " z kompletem opon zimowych";
  81. }
  82. public double PodajCene()
  83. {
  84. return pojazd.PodajCene() + 1500;
  85. }
  86. }
  87. }