Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c#: abstract class using interfaces
- public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
- {
- private string name;
- public MyClass(string name)
- {
- this.name = name;
- }
- }
- public interface IPartImportsSatisfiedNotification
- {
- void SomeMethod();
- }
- public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
- {
- private string name;
- public MyClass(string name)
- {
- this.name = name;
- }
- public abstract void SomeMethod();
- public abstract void Dispose();
- }
- public class SubClass : MyClass
- {
- public SubClass(string someString) : base(someString)
- {
- }
- public override void SomeMethod()
- {
- throw new NotImplementedException();
- }
- public override void Dispose()
- {
- throw new NotImplementedException();
- }
- }
- public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
- {
- private string name;
- public MyClass(string name)
- {
- this.name = name;
- }
- public abstract void Dispose();
- }
- public abstract void Dispose(); // implements IDisposable
- void Main()
- {
- DerivedClass dc = new DerivedClass("hello, world");
- Console.Out.WriteLine(dc);
- string result = dc.Notify("greetings");
- Console.Out.WriteLine(result);
- }
- public interface IPartImportsSatisfiedNotification
- {
- string Notify(string msg);
- }
- public abstract class MyClass : IPartImportsSatisfiedNotification
- {
- protected string name;
- public MyClass(string name)
- {
- this.name = name;
- }
- abstract public string Notify(string msg);
- }
- public class DerivedClass : MyClass
- {
- public DerivedClass(string name) :base(name)
- {
- }
- public override string Notify(string msg)
- {
- return string.Format("Msg {0} from {1}", msg, this.name);
- }
- public override string ToString()
- {
- return this.name;
- }
- }
Add Comment
Please, Sign In to add comment