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 ответов

31 просмотр

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)

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
Как передать управляющий символ в открытую через CreateProcess консоль? Собсна, есть процедура: procedure TRedirectThread.WriteData(Data: OEMString); var Written: Cardinal;...
Serjone
6
program test; {$mode delphi} procedure proc(v: int32); overload; begin end; procedure proc(v: int64); overload; begin end; var x: uint64; begin proc(x); end. Уж не знаю...
notme
6
Ребят в СИ можно реализовать ООП?
Николай
33
у вас два процесса. один посылает другому сигнал. у вас есть код обоих процессов? если всё не так - расскажите как оно на самом деле. а именно кто кому чего, есть-ли консоли,...
Karagy
6
вы делали что-то подобное и как? может есть либы готовые? увидел картинку нокода, где всё линиями соединено и стало интересно попробовать то же в ddl на lua сделать. решил с ч...
Victor
8
Карта сайта