0

When we write a programme using java, we can start writing an interface, abstract class, and next to a concrete class. But without writing interface and abstract class, we can just write the concrete class with all implementations. When should I write an interface, an abstract class with a concrete class?. Because I always write interface and abstract class just as a practice and follow the oop concept. Please explain to me.

Vinee-the-Pooh
  • 627
  • 1
  • 6
  • 19
  • 1
    This really depends on what you're doing. For example, writing an interface that will be used only by a single class seems kind of stupid IMO. – Some programmer dude Aug 24 '18 at 10:45
  • 2
    @Someprogrammerdude that actually depends, e.g. if you want to use the interface to hide some implementation details, e.g. methods that should not be visible to whoever uses the interface. But you're right in general: an interface should serve a purpose otherwise it's unnecessary bloat. – Thomas Aug 24 '18 at 10:48

0 Answers0