you have one method that is used by N number of classes. If the definition is different from each class, use the interface.
Let's say one method is similar for 50 classes, and another 50 classes have different behaviors that use an abstract class. You define a method.
And use for the first 50 classes, and the remaining 50 classes have different behavior, so redefine the existing method in accordance with the class behavior.
Example
Interface Graphics { void size(); void draw(); } Class Rectangle implements Graphics { void size() { x=10; y=10; } void draw() { ..... } } class Triangle implements Graphics { void size() { x=10; y=10; } void draw() { ..... } }
so both sizes are the same for both classes and then use abstract
abstract class Graphics { void size() { x=10; y=10; } abstract void draw(); }
Then, if any class extends this class, the size is similar and defines only draw() If some classes need a different position, then override the size.
source share