Author Topic: A few questions about Interfaces : Part 1  (Read 1813 times)


  • Hero Member
  • *****
  • Posts: 827
    • HowTos Considered Harmful?
A few questions about Interfaces : Part 1
« on: March 05, 2016, 11:38:30 pm »
Would it be correct to say that for an object to implement a certain interface means that its supports a number of Procedureal Types of 'procedure of object' items, the main difference being that their names are known beforehand?

Does a unit which depends on the  interfaced object need to be compiled with that unit, or does need only a unit where that interface type is declared?

Taking this code posted at :

Code: Pascal  [Select][+][-]
  2.  type
  3.    // An interface definition
  4.    IRecyclable = Interface(IInterface)
  5.      // A single function supporting the property
  6.      function GetIsRecyclable : Boolean;
  7.      // A single property
  8.      property isRecyclable : Boolean read GetIsRecyclable;
  9.    end;

Say the above snippet is in unit A and some routine in unit B needs to use an object TSomeObject from unit C which implements IRecyclable.

Is it necessary for unit B to be compiled with support for unit C if the routine in unit B needs to use only the IRecyclable properties of TSomeObject, but not the remaining properties? Say some code in B is passed a parameter of an unknown type such as TSomeObject that implements IRecyclable and has some code like :

Code: Pascal  [Select][+][-]
  1. if var is IRecyclable then
  2.   if var.IsRecylable then
  3.    ...

Is this one of the main rationales for interfaces?
Windows - Lazarus 1.0.8/FPC 2.6.0
Linux - Lazarus 1.4.4 /FPC 2.6.4


  • Hero Member
  • *****
  • Posts: 5365
Re: A few questions about Interfaces : Part 1
« Reply #1 on: March 06, 2016, 06:37:15 am »
Please make sure your parameters are type safe (ee param1:IRecyclable) and do not use variants unless absolutely necessary. To answer your question it depends on the code you write if you stay inside the interface then you only need to reference unit that has the interface definition.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64


TinyPortal © 2005-2018