Reputation: 123
I have an abstract base class with an interface.
interface ISubmit {
bool SubmitFile();
}
public abstract class SubmitMaster : ISubmit {
public abstract bool SubmitFile();
}
public class SubmitRoute : SubmitMaster {
public override bool SubmitFile() {
//...
}
}
The base class has some other implemented methods used by the child classes, but I need to ensure that each child class has the SubmitFile() method and each one needs its own block for it. Currently, its working just fine, but I feel that what I've done is rather redundant. Do I even need the interface? Or is making the base class and SubmitFile() abstract the wrong move?
What is the best practice in this case?
Upvotes: 2
Views: 3423
Reputation: 64933
In your case that interface is absolutely redundant.
Perhaps I would still maintain an interface like this if it should be implemented by other classes not necessarily being derived from SubmitMaster
abstract class.
Or if the interface is part of your API and you don't need to expose all members of SubmitMaster
abstract class wherever you need to use SubmitFile
method.
In fact, I could throw here tons of reasons where the interface would be useful, but if you're just defining an interface to implement it in an abstract class, and you never type your references as the so-called interface, then, again, it's absolutely redundant.
Further reading:
Upvotes: 1
Reputation: 659956
What is the best practice in this case? Do I even need the interface?
Are you planning on making, lets say at least three types that have no relation to each other whatsoever, but nevertheless all can be used as ISubmit?
For example, suppose we have an interface that represents a sequence. I can give you a dozen completely unrelated classes that are all sequences. Arrays, lists, dictionaries, trees, blah blah blah, they are all sequences. So we make an interface that represents a sequence, IEnumerable.
If you are not planning on making a bunch of unrelated things that have a usage case in common then don't use an interface.
Upvotes: 1