169 похожих чатов

What is the difference between overriding methods of an interface

and overriding methods of an abstract class?
are abstract classes and interfaces the same thing? if they are, why fpc has both of them?

12 ответов

35 просмотров

These are different things, but their applications often overlap. Sometimes architecture using interfaces can be replaced with architecture using base classes. But not always

Αλι-(EN, EO) Автор вопроса
Αλι (EN, EO)
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

Αλι-(EN, EO) Автор вопроса
Renat Suleymanov
You can create it, but the IDE will warn you that ...

shouldn't the compiler throw compile time error for this instead of warning? because at run-time it will always be an error 🤔

Αλι (EN, EO)
shouldn't the compiler throw compile time error fo...

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)

Renat Suleymanov
Wrong. There is no abstract class in reality. It's...

In Delphi you can declare abstract classes: TAbc = class abstract! Is this not possible in FPC/Lazarus?

It seems there is such a thing. But I didn't use it, I repeat

Renat Suleymanov
It seems there is such a thing. But I didn't use i...

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

Thomas
In Delphi you can declare abstract classes: TAbc =...

Thank you for discovering another Pascal feature for me)

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
14
Добрый день! Скажите пожалуйста, а какие программы вы бы рекомендовали написать для того, чтобы научиться управлять памятью? Можно написать динамический массив, можно связный ...
Филипп
7
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
Ребят в СИ можно реализовать ООП?
Николай
33
https://github.com/erlang/otp/blob/OTP-27.1/lib/kernel/src/logger_h_common.erl#L174 https://github.com/erlang/otp/blob/OTP-27.1/lib/kernel/src/logger_olp.erl#L76 15 лет назад...
Maksim Lapshin
20
Карта сайта