Having iEvent<T> and TEvent<T> declared in one unit

Issue #150 wontfix
Arioch The created an issue

I'd like to use both TEvent<T> (for creation) and iEvent<T> (for storing) types and keep uses section minimal, thus only adding Spring or Spring.Events unit to the uses clause.

One possible solution is to use Event<T> wrapper. Possible - but wrapper is wrapper. Extra runtime checks and kind of stands out of the code that mostly uses interface types.

proposal: add one line into TEvent<T> declaration

unit Spring.Events;
...
{$IFDEF SUPPORTS_GENERIC_EVENTS}
  TEvent<T> = class(TEvent, IEvent<T>)
  public
      type Intf = Spring.IEvent<T>;      (********************)
  private
    function GetInvoke: T;
.......

The application code then can only add Spring.Events unit to USES and declare objects like

type 
  TDummyChangeNotifier = TNotifyEvent; // or something extended and customised

  TDummy = class
  public
      OnChange: TEvent< TDummyChangeNotifier >.Intf;
  ....

  constructor TDummy.Create;
  begin
     OnChange := TEvent< TDummyChangeNotifier >.Create;
  ....

Comments (2)

  1. Stefan Glienke repo owner

    The purpose to separate interface and implementation is to - well separate them. Thus putting the interface into the implementing class to save a unit in the uses is not an option.

  2. Arioch The reporter

    Then what about Event<T> from the Spring.pas - that is both interface AND the implementation.

    Okay, what about iEvent<T> creating function in Spring.pas ? If "Spring.Events" is implementation detais, I am okay about forgetting it, but then function to create instans in iEvent<T> should be in Spring.pas itself

    just like Event<T> can be created by using only Spring.pas

  3. Log in to comment