-2

It happens quite often that I have an abstract class that is pretty much an interface, save for a few trivial methods (say an average(array) method).

In these cases, does it make sense to create an interface, so that the abstract class implements it?

lfk
  • 2,423
  • 6
  • 29
  • 46
  • It is difficult to answer unless you explain the scenario you are designing for. Your current description will attract only opinion based answers. At the least post the class definition you have so far. – Nikhil Vartak Jun 03 '17 at 19:47

1 Answers1

1

You don't need an interface for everything. An abstract class is fine. In some languages you can "implement" several classes and "extend" only one. So only if you have a case where you want to use multiple inheritance, then go ahead and make an interface for it. Otherwise, don't bother and just keep things simple.

If you use languages like C++, then there is no difference between an interface and an abstract class, so you can see that it doesn't really matter.

Note that there is also a question about it here: Interface or an Abstract Class: which one to use?

Stewart
  • 4,356
  • 2
  • 27
  • 59
  • 1
    Thanks. Other questions are mostly about the difference of abstract class and interface. Mine was more about when to use both. – lfk Jun 05 '17 at 10:32