and overriding methods of an abstract class?
are abstract classes and interfaces the same thing? if they are, why fpc has both of them?
These are different things, but their applications often overlap. Sometimes architecture using interfaces can be replaced with architecture using base classes. But not always
can you point out their differences?
In my own words? After all, you can read all this in the wiki 1. An interface is like a declaration of intent. A class is not a perfect solution for multiple inheritance either 2. A class, even with abstract procedures, is still a class that can create objects. It's like a ready-made base class for implementing functionality by its heirs 3. The interface can be used, for example, when there is no access to the base class or its modification does not correspond to the style of the library or application architecture, but there are two similar classes with similar properties and procedures, which it would be nice to combine into a new class. I often use the interface for this.
You can create it, but the IDE will warn you that you have unrealized abstract procedures. If they are randomly called, a runtime error will also be generated. Sometimes, instead of abstract procedures, you can even do an empty procedure, sometimes a specific error generation is placed in it. Depends on the architecture
shouldn't the compiler throw compile time error for this instead of warning? because at run-time it will always be an error 🤔
Wrong. There is no abstract class in reality. It's purely on a specific architecture, we can call it that. The compiler cannot know that a class is abstract by itself. But procedures and functions can be abstract by definition. And it is when they are called that an error will be generated. But it may happen that an abstract procedure from this class should not be called in this instance (although the architecture is not quite right for me then)
great. thank you 👍
In Delphi you can declare abstract classes: TAbc = class abstract! Is this not possible in FPC/Lazarus?
I can't say offhand, I've never used)
It seems there is such a thing. But I didn't use it, I repeat
In this case, the abstract class is even closer to the interfaces in terms of scope. But these are still different things in principle. Interfaces succinctly solve the problem of multiple inheritance for me, with the help of abstract classes, it often looks like the invention of a bicycle
Thank you for discovering another Pascal feature for me)
Обсуждают сегодня