I have an abstract class with a public abstract method on it. I’m wondering if I should just define an interface and have the abstract class implement that instead. Is there a general rule of thumb here? Currently it works just fine, but I want to be mindful of OO conventions. This is currently how it looks:
public abstract class MySuckyClass
{
public bool TryGetMember(GetMemberBinder binder, out object result)
{
result = this.GetMember(binder.Name);
if (result == null)
return false;
return true;
}
public abstract object GetMember(string memberName);
}
You’re asking a question which has a range of different answers. Will probably vary based on opinion.
Personally, I like defining interfaces and then supplying some canned functionality using an abstract class. This allows me to go back to the interface if I need to supply a different implementation, but saves me time when dealing with methods/properties that do the same thing in multiple implementations.