fork(2) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. IComputer computer = new KeyBoard(new Monitor(new Disk(new Computer())));
  8.  
  9. Console.WriteLine(" You are getting a " + computer.getComputer());
  10. }
  11. }
  12.  
  13. public interface IComputer
  14. {
  15. string getComputer();
  16. }
  17.  
  18. public sealed class Computer : IComputer
  19. {
  20. public string getComputer()
  21. {
  22. return "computer";
  23. }
  24. }
  25.  
  26. public class Disk : IComputer
  27. {
  28. IComputer computer;
  29. public Disk(IComputer c)
  30. {
  31. computer = c;
  32. }
  33.  
  34. public String getComputer()
  35. {
  36. return computer.getComputer() + " and a disk";
  37. }
  38. }
  39.  
  40. public class Monitor : IComputer
  41. {
  42. IComputer computer;
  43. public Monitor(IComputer c)
  44. {
  45. computer = c;
  46. }
  47.  
  48. public String getComputer()
  49. {
  50. return computer.getComputer() + " and a Monitor";
  51. }
  52. }
  53.  
  54. public class KeyBoard : IComputer
  55. {
  56. IComputer computer;
  57. public KeyBoard(IComputer c)
  58. {
  59. computer = c;
  60. }
  61.  
  62. public String getComputer()
  63. {
  64. return computer.getComputer() + " and a KeyBoard";
  65. }
  66. }
  67.  
Success #stdin #stdout 0.02s 33856KB
stdin
Standard input is empty
stdout
 You are getting a computer and a disk and a Monitor and a KeyBoard