Answer the question
In order to leave comments, you need to log in
Why use an interface?
Almost always it turns out that I use an interface and classes that implement it. But when suddenly there is a need for an abstract class, it immediately becomes blunt to what to apply the interface to: to the implementing class:
class FooService extends AbstractFooService implements FooServiceInterface {}
abstract class AbstractFooService implements FooServiceInterface {}
class FooService extends AbstractFooService {}
Answer the question
In order to leave comments, you need to log in
An interface describes a contract.
An abstract class describes the basic behavior that is common to multiple descendants.
What is the problem?
Do not be afraid of abstract classes, it can be very convenient, the interface does not contain an implementation, it cannot have properties, only constants. Also, the interface has only public methods, when an abstract class can contain some private methods, where the general logic will be contained.
I am for the second option
the first option is correct. I don't understand what is the problem
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question