fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. person xc= new person("小草");
  8. Console.Write("\n 第一种装版");
  9.  
  10.  
  11. TShirts tt=new TShirts();
  12. BigT bt =new BigT();
  13.  
  14. tt.decorate(xc);
  15. bt.decorate(tt);
  16. tt.show();
  17.  
  18. }
  19. }
  20.  
  21.  
  22. class person
  23. {
  24. private string name;
  25.  
  26. public person()
  27. {
  28.  
  29. }
  30.  
  31. public person(string n)
  32. {
  33. this.name=n;
  34. }
  35.  
  36. public virtual void show()
  37. {
  38. Console.WriteLine("装扮的{0},name");
  39. }
  40. }
  41.  
  42. class Finery:person
  43. {
  44. protected person compon;
  45. public void decorate(person p)
  46. {
  47. this.compon=p;
  48. }
  49.  
  50. public override void show()
  51. {
  52. if(compon != null)
  53. {
  54. compon.show();
  55. }
  56. }
  57.  
  58. }
  59.  
  60. class TShirts : Finery
  61. {
  62. public override void show()
  63. {
  64. Console.Write("大T恤");
  65. base.show();
  66. }
  67. }
  68.  
  69. class BigT : Finery
  70. {
  71. public override void show()
  72. {
  73. Console.Write("裤子");
  74. base.show();
  75. }
  76. }
Success #stdin #stdout 0.04s 28500KB
stdin
Standard input is empty
stdout
 第一种装版大T恤装扮的{0},name