Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language    [ Add a report in this area ]  
Report #:  106617   Status: Open
Allow automatic / implied implementation of getters and setters
Project:  Delphi Build #:  XE2
Version:    16.4 Submitted By:   Tim Kelly
Report Type:  Suggestion / Enhancement Request Date Reported:  6/22/2012 11:14:21 AM
Severity:    Commonly encountered problem Last Updated: 8/6/2012 10:35:02 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
Interface property implementation in Delphi is currently extremely cumbersome. A single read/write property declared in an interface and implemented in a class currently requires:

Interface:
1 x getter definition
1 x setter definition
1 x property definition

Class:
1 x getter definition
1 x setter definition
1 x property definition
4 x lines getter implementation
4 x lines setter implementation

= 15 lines of code!!! This is ridiculous, and should stop with XE3.

I have a unit with 5 classes and 10 properties in each class.. it is over 1000 lines of code just dealing with standard getters and setters. It's annoying because the real code that does stuff gets lost. You can't see the wood through the trees.

It discourages use of interfaces, I notice my source files triple in length switching to an interface based paradigm.

This is totally un-necessery as 99% of the time one follows a standard getter / setter design pattern.

I therefore propose the introduction of a new keyword, for example stdimpl, with the level of protection placed in brackets, protected being the default.

Using this keyword instead of a getter / setter method implies that the getter / setter is to be implemented by the compiler using well established standard getter / setter implementations.

Example:

ICustomer = interface
  property Name : string read stdimpl write stdimpl;
end;

TCustomer = class(TInterfacedObject, ICustomer)
  public
  property Name : string read stdimpl write stdimpl(private);
end;

The above would cause the compiler to generate code exactly equivelent to this:

ICustomer = interface
  function GetName : string;
  procedure SetName(const Value : string);
  property Name : string read GetName write SetName;
end;

TCustomer = class(TInterfacedObject, ICustomer)
  protected
    function GetName : string;
  private
    procedure SetName(const Value : string);  
  property Name : string read GetName write SetName;
end;

I propose these compiler generated methods and functions would really exist and would be found if you for example used RTTI to look for them. The only problem I see if with debugging as there would be no corresponding source lines for the methods which I propose injecting, but I don't think this should be a showstopper.
Steps to Reproduce:
None
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01