Answer the question
In order to leave comments, you need to log in
If it were possible to implement the desired methods in an interface without the need for implementation in descendants, then would abstract classes be needed?
I want to understand the specific purposes of interfaces / abstract classes and what and where can be used
Answer the question
In order to leave comments, you need to log in
In order to understand the difference between abstract classes and interfaces, it is worth starting a little away from their implementation for a specific programming language and understanding their essence.
What is an interface? it is a specification of how the outside world interacts with an object. Pay attention to INTERACTIONS, but not implementations.
Let's take for example an ordinary class that describes some kind of switch (i.e., the task of such a class is to turn on or off some device):
public class Switch
{
public void On()
{
// тут предполагается куча кода для включения устройства
}
public void Off()
{
// тут предполагается куча кода для выключения устройства
}
}
public interface ISwithable
{
public void On()
public void Off()
}
In general, detailed answers have already been given, I once remembered the following statement on this issue:
And in Kotlin there is an opportunity for some interface methods to specify the default implementation :)
kotlinlang.ru/docs/reference/interfaces.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question