Guest User

Untitled

a guest
Aug 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. c#: abstract class using interfaces
  2. public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
  3. {
  4. private string name;
  5. public MyClass(string name)
  6. {
  7. this.name = name;
  8. }
  9. }
  10.  
  11. public interface IPartImportsSatisfiedNotification
  12. {
  13. void SomeMethod();
  14. }
  15.  
  16. public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
  17. {
  18. private string name;
  19. public MyClass(string name)
  20. {
  21. this.name = name;
  22. }
  23.  
  24. public abstract void SomeMethod();
  25.  
  26. public abstract void Dispose();
  27. }
  28.  
  29. public class SubClass : MyClass
  30. {
  31. public SubClass(string someString) : base(someString)
  32. {
  33.  
  34. }
  35.  
  36. public override void SomeMethod()
  37. {
  38. throw new NotImplementedException();
  39. }
  40.  
  41. public override void Dispose()
  42. {
  43. throw new NotImplementedException();
  44. }
  45. }
  46.  
  47. public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
  48. {
  49. private string name;
  50. public MyClass(string name)
  51. {
  52. this.name = name;
  53. }
  54.  
  55. public abstract void Dispose();
  56. }
  57.  
  58. public abstract void Dispose(); // implements IDisposable
  59.  
  60. void Main()
  61. {
  62. DerivedClass dc = new DerivedClass("hello, world");
  63. Console.Out.WriteLine(dc);
  64. string result = dc.Notify("greetings");
  65. Console.Out.WriteLine(result);
  66. }
  67.  
  68.  
  69.  
  70. public interface IPartImportsSatisfiedNotification
  71. {
  72. string Notify(string msg);
  73. }
  74.  
  75.  
  76.  
  77. public abstract class MyClass : IPartImportsSatisfiedNotification
  78. {
  79. protected string name;
  80. public MyClass(string name)
  81. {
  82. this.name = name;
  83. }
  84.  
  85. abstract public string Notify(string msg);
  86.  
  87. }
  88.  
  89. public class DerivedClass : MyClass
  90. {
  91. public DerivedClass(string name) :base(name)
  92. {
  93.  
  94. }
  95.  
  96. public override string Notify(string msg)
  97. {
  98. return string.Format("Msg {0} from {1}", msg, this.name);
  99. }
  100.  
  101. public override string ToString()
  102. {
  103. return this.name;
  104. }
  105. }
Add Comment
Please, Sign In to add comment