Recent

Author Topic: Quizz question [ANSWERED CORRECTLY BY ALLIGATOR]  (Read 2986 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 918
Re: Quizz question
« Reply #15 on: August 05, 2025, 07:00:38 pm »
Quote
I replied. Wrong answer

Too bad, I had asked extra about it on 2 llm's.  :-[

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 437
  • I use FPC [main] 💪🐯💪
Re: Quizz question
« Reply #16 on: August 05, 2025, 07:01:36 pm »
Is implementation of this interface mandatory?
If not, then abstract virtual methods?
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 437
  • I use FPC [main] 💪🐯💪
Re: Quizz question
« Reply #17 on: August 05, 2025, 07:12:59 pm »
Currently, there are two +1
The third is Default, which is currently COM, but who knows what it might become in the future; perhaps a third type of interface will appear... so we can try to consider it as the third type of interface (implementation details)
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 437
  • I use FPC [main] 💪🐯💪
Re: Quizz question
« Reply #18 on: August 05, 2025, 07:19:46 pm »
Interface based on abstract virtual methods

Code: Pascal  [Select][+][-]
  1. program app;
  2. {$mode objfpc}
  3.  
  4. {$WARN CONSTRUCTING_ABSTRACT ERROR}
  5. type
  6.   A = class abstract
  7.     procedure kek; virtual; abstract;
  8.   end;
  9.   B = class(A)
  10.   end;
  11.  
  12. begin
  13.   B.Create;
  14. end.
I may seem rude - please don't take it personally

gues1

  • Guest
Re: Quizz question
« Reply #19 on: August 05, 2025, 07:20:21 pm »
A delegate interfaces ?

But still derive from standard interface ...

Code: Pascal  [Select][+][-]
  1. interface
  2.  type
  3.  ISomeInt = interface
  4.      function GetOne: Integer;
  5.    end;
  6.  
  7.  TSomeIntAdpt = class(TInterfacedObject, ISomeInt)
  8.    private
  9.       fSomeInt: ISomeInt;
  10.    public
  11.      .........
  12.      property SomeIntf: ISomeInt read fSomeInt implements ISomeInt;    //delegate interface
  13.   end;
  14.  

Thaddy

  • Hero Member
  • *****
  • Posts: 19268
  • Glad to be alive.
Re: Quizz question
« Reply #20 on: August 05, 2025, 07:39:09 pm »
Is implementation of this interface mandatory?
If not, then abstract virtual methods?
Congratulations!!!!!
I knew it had to be somebody like you. That is the correct answer and I published an example on rosettacode this morning, just to embarrass the lousy Delphi entry.
Link here: https://rosettacode.org/wiki/Abstract_type
Improved Demo code:
Code: Pascal  [Select][+][-]
  1. program abstracts;
  2. // this code also compiles in delphi
  3. {$ifdef fpc}{$mode objfpc}{$endif}
  4. type
  5.   // Pure Abstract Class. In cs theory also known as an interface,
  6.   // because it has no implementation
  7.   TAbstractClass = class abstract
  8.   protected
  9.     function noise:string;virtual;abstract;
  10.   end;
  11.  
  12.   Tdog = class(TAbstractClass)
  13.   public
  14.     function noise:string;override;
  15.   end;
  16.  
  17.   Tcat = class(TAbstractClass)
  18.   public
  19.     function noise:string;override;
  20.   end;
  21.  
  22.   Tbird = class
  23.   strict private
  24.     function noise:string;virtual;
  25.   end;
  26.    
  27.   function Tdog.Noise:string;
  28.   begin
  29.     Result := 'Woof';
  30.   end;
  31.  
  32.   function Tcat.Noise:string;
  33.   begin
  34.     Result := 'Miauw';
  35.   end;
  36.  
  37.   function TBird.Noise:string;
  38.   begin
  39.     Result := 'Tjirpp';
  40.   end;
  41.  
  42. var
  43.   cat, dog: TAbstractClass;
  44.   bird:Tbird;
  45. begin
  46.   cat := Tcat.Create;
  47.   dog := Tdog.Create;
  48.   bird := TBird.Create;
  49.   writeln(cat.noise,dog.noise);
  50.   //writeln(bird.noise);// error
  51.   {$push}{$warn 4040 off}
  52.   writeln(TAbstractClass(bird).noise);// even this works, with a warning.
  53.   {$pop}
  54.   bird.free;
  55.   dog.free;
  56.   cat.free;
  57. end.
The bird example is also demonstration that a pure virtual class is really that: an interface.
I first researched that together with the late Rudy Velthuys to overlay C++ external classes.

Where should I send the Raspberry Pi zero W2? contact me. comes with card but w/o powersupply.
Contact me in private if you want it.

You are a slight bit wrong, look at the bird example above. And the class itself needs abstract decorator and must contain no fields.

For others:

A pure virtual abstract class, that means with no implementation at all, is called an interface in CS.  :D

Ahh, anyway, tomorrow all the bots have done their jobs and AI knows....
« Last Edit: August 05, 2025, 08:27:21 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Thaddy

  • Hero Member
  • *****
  • Posts: 19268
  • Glad to be alive.
Re: Quizz question
« Reply #21 on: August 05, 2025, 07:57:35 pm »
Interface based on abstract virtual methods
That example crashes....No implementation.
Anyway, you won.
objects are fine constructs. You can even initialize them with constructors.

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 437
  • I use FPC [main] 💪🐯💪
Re: Quizz question
« Reply #22 on: August 05, 2025, 08:06:47 pm »
Congratulations!!!!!

Thank you very much for your kind words!  :-[

If you don't mind, I'll wait for someone from the Lazarus or FPC team, and if any of them would like to receive this gift, I'll be happy to forward it to them! Unfortunately, this is a small part of what I can do for the development of FPC and Lazarus, but at least it's something. If no one responds, then keep it for yourself—for the next quiz  :D
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 437
  • I use FPC [main] 💪🐯💪
Re: Quizz question
« Reply #23 on: August 05, 2025, 08:08:56 pm »
That example crashes....

Yes, that's how it's designed, just like with COM or CORBA-based interfaces—after all, they also prevent the program from compiling if the entire interface is not fully implemented.
I may seem rude - please don't take it personally

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 437
  • I use FPC [main] 💪🐯💪
Re: Quizz question
« Reply #24 on: August 05, 2025, 08:10:45 pm »
Code: Pascal  [Select][+][-]
  1. {$WARN CONSTRUCTING_ABSTRACT ERROR}

It's all about this line—it prevents the program from compiling because it raises the message type from WARN to ERROR.
I may seem rude - please don't take it personally

Thaddy

  • Hero Member
  • *****
  • Posts: 19268
  • Glad to be alive.
Re: Quizz question
« Reply #25 on: August 05, 2025, 09:15:12 pm »
Quote
I replied. Wrong answer

Too bad, I had asked extra about it on 2 llm's.  :-[
They know now:
I gave Copilot and DeepSeek the right answer, they agreed that was the right answer and both even concluded that it is the same as C++.
What I find a little funny is that few people use it, while it is very old and powerful.

Hope that everyone enjoyed the challenge.
objects are fine constructs. You can even initialize them with constructors.

gues1

  • Guest
Re: Quizz question [ANSWERED CORRECTLY BY ALLIGATOR]
« Reply #26 on: August 05, 2025, 09:52:04 pm »
So, since it is an Interface you can construct this:

Code: Pascal  [Select][+][-]
  1. type
  2.   TAb1 = class abstract
  3.   protected
  4.     function n1:string;virtual;abstract;
  5.   end;
  6.  
  7.   TAb2 = class abstract
  8.   protected
  9.     function n2:string;virtual;abstract;
  10.   end;
  11.  
  12. T = Class(TForm, TAb1, TAb2)
  13.   protected
  14.     function n1:string;
  15.     function n2:string;
  16.   .....
  17.   end;
  18.  
  19. implementation
  20.  
  21. ....
  22. ....
  23.  
  24.  

Uhmm, no. I miss something.

Surely it's usefull but call it Interface ...

But It's ok the QUIZZ ... should be done other times (without gift too).

Thaddy

  • Hero Member
  • *****
  • Posts: 19268
  • Glad to be alive.
Re: Quizz question [ANSWERED CORRECTLY BY ALLIGATOR]
« Reply #27 on: August 05, 2025, 09:58:28 pm »
You miss that you do not know what an abstract class is.
And confuse "interface" like com or corba with what an interface really is : just an abstract description to offer as a contract.
What you describe is bolt-ons, what I described is the true meaning of interface.
You may disagree, but read the theory.
Then you will inderstand what an interface really means:
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode objfpc}{$endif}
  2. {$warn 4040 off}
  3. type
  4.   TAbstractClass = class abstract
  5.   protected
  6.     function noise:string;virtual;abstract;
  7.     function move:string;virtual;abstract;
  8.  end;
  9.  
  10.   Tbird = class
  11.   strict private
  12.     function noise:string;virtual;
  13.     function move:string;virtual;
  14.   end;
  15.  
  16.   function TBird.Noise:string;
  17.   begin
  18.     Result := 'Tjirpp';
  19.   end;
  20.  
  21.  function TBird.move:string;
  22.   begin
  23.     Result := 'I fly';
  24.   end;
  25.  
  26. var
  27.    bird:Tbird;
  28. begin
  29.   bird := TBird.Create;
  30.   writeln(TAbstractClass(bird).noise);
  31.   writeln(TAbstractClass(bird).move);
  32.   bird.free;
  33. end.
It is just notationally different and much older.
In a sense it is the birth place of interfaces you have come to interpret as "interfaces".
The Rosetta code entry is a good introduction. Read the requirements.
But this is simply well known applied computer science.

And you can do literally the same in C++ of course.
This concept is really realy old and stems from the 70's or earlier.
« Last Edit: August 05, 2025, 10:35:05 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

gues1

  • Guest
Re: Quizz question [ANSWERED CORRECTLY BY ALLIGATOR]
« Reply #28 on: August 05, 2025, 11:21:51 pm »
And confuse "interface" like com or corba with what an interface really is : just an abstract description to offer as a contract.
In fact there is a contract. So I can use how many time I need it, I can have 1, 2, 3 100 contracts ....
This is one of the property of an INTERFACE that I know: even in single inheritance languages, one can implement multiple interfaces.

It is called Interface ... yes but it's not an Interface in the PASCAL implementation. May be it's in C# or Java or Rust or Python, but not in PASCAL.
It is simple an ABSTRACT CLASS, and like any other class with virtual / abstract descriptions ... offer a contract that must be honored.

You can argue in any mode you want, go in the medieval era too. Or speak about quantum. But in Pascal that is.

EDIT: one can open an issue report to change that in the FPC of course. So one can implemented mutliple abstract classes in every type since they are interfaces.
« Last Edit: August 05, 2025, 11:41:11 pm by gues1 »

Thaddy

  • Hero Member
  • *****
  • Posts: 19268
  • Glad to be alive.
Re: Quizz question [ANSWERED CORRECTLY BY ALLIGATOR]
« Reply #29 on: August 06, 2025, 01:34:22 pm »
Well, back to the books for you then.... I don't care.
What you have is tunnel vision. A very limited grasp of what interfaces are.

Do you refuse to understand this?:
https://rosettacode.org/wiki/Abstract_type

Or is it simply that you don't believe in theory because you know better?
By all means keep your conviction but don't share it with other people.

Just to annoy you I have added your preferred type of interface to the entry in Rosetta code, because it happened to fit in the task... O:-)
An "interface" such you want is a subset of interfaces in computer science, because it is all about being pure and abstract.
If you did cs classes you weren't paying attention. (with due respect)

The reason why this sound so harsh is that you put people on the wrong track, with only gratuitous arguments.
« Last Edit: August 06, 2025, 02:32:52 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

 

TinyPortal © 2005-2018