Advice Needed: When to Use Abstract Classes and When Interfaces?
Posted by Soumyar-Tripathy@reddit | learnprogramming | View on Reddit | 2 comments
I'm a student currently in my third semester, focusing a lot on Java in my studies. I'm aware of the syntax guidelines that abstract classes may include instance variables and constructors whereas interfaces have purely abstract implementations. But, whenever I start working on designing a small program, I find myself stuck between deciding whether to choose an interface or an abstract class. Is there any particular rule or principle that guides your approach here?
Danque62@reddit
I guess whenever you want a method that is commonly executed on the sub classes, since one of the differences is that an abstract class can have a method not be abstract.
lurgi@reddit
I have almost never used abstract classes. I haven’t made an exact count, but I would guess that interfaces outnumber abstract classes 70 to 1 in my code.