Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Interfaces    [ Add a report in this area ]  
Report #:  106535   Status: Open
Implicit Defined Interfaces
Project:  Delphi Build #:  16.0.4429.46931
Version:    16.4 Submitted By:   Günther Weber
Report Type:  New Feature Request Date Reported:  6/19/2012 10:03:39 AM
Severity:    Commonly encountered problem Last Updated: 8/6/2012 10:36:28 AM
Platform:    All platforms Internal Tracking #:  
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
* Requirements *

The compiler should be able to define an interface from the declaration of a class:

type
  TMyObject = class(TInterfacedObject)
    defines IMyObject
        ['{8A843D39-F79C-4EF4-AB6C-FA6FB689F913}']
  private
     function GetIsReadOnly: Boolean;
  public
    procedure Clear;
    property IsReadOnly: Boolean read GetIsReadOnly;
  end;

The implicit defined interface (IMyObject) should contain all public methods (except constructors and destructors) and all public/published properties.

Inherited Members may be ignored (Don't want all that stuff from TObject).

Such an implicit interface defnition may restrict the defining class to the same constraints of interfaces. E.g. properties must have getter/setter-methods.


* Rationale and Use Cases *

1. Unite two worlds: objects and interfaces

The main problem in using interfaces as an instrument for your software design is the fact, that it is not recommended to use both object- and interface-references for the same object.

With the approach of the implicit interfaces you can always use interface-references for your objects.

2. As an lightweight alternative to Garbage Collection

Livetimemangement of Objects specifically in multi-threaded Applications is often error-prone.
Currently Delphi offers reference counted interfaces that can be (and of course are) used for livetimemanagement. So what we regularly see is code like this:

type
  IMyMessage = interface
    function GetIsReadOnly: String;
    function GetMessageID: Integer;
    procedure Processed;
    property MessageText: String read GetIsReadOnly;
    property MessageID: Integer read GetMessageID;

  end;

  TMyMessage = class(TInterfacedObject, IMyObject)
  private
    function GetIsReadOnly: String;
    function GetMessageID: Integer;
  public
    constructor Create(AId: Integer; AText: String);
    procedure Processed;
    property MessageText: String read GetIsReadOnly;
    property MessageID: Integer read GetMessageID;

  end;

Maintainig such kind of code is not very funny!
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01