Moved signal interfaces inside records

This commit is contained in:
Michael Schimmel
2025-06-05 23:27:48 +02:00
parent 7ba42b0c7c
commit a57b2d50e4
15 changed files with 316 additions and 313 deletions
+16 -16
View File
@@ -10,7 +10,7 @@ uses
type
// TMycNullSignal implements a "null object" pattern for IMycState.
// This state is always considered "set".
TMycNullSignal = class(TInterfacedObject, IMycSignal)
TMycNullSignal = class(TInterfacedObject, TSignal.ISignal)
public
function Subscribe(Subscriber: IMycSubscriber): Pointer;
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
@@ -18,14 +18,14 @@ type
// TMycNullState implements a "null object" pattern for IMycState.
// This state is always considered "set".
TMycNullState = class(TMycNullSignal, IMycState)
TMycNullState = class(TMycNullSignal, TState.IState)
protected
// IMycState
// TState.IState
function GetIsSet: Boolean;
end;
// A state that acts as an event. It's state ist always set and it will always Trigger it's subscribers, if it gets notified by itself.
TMycEvent = class(TInterfacedObject, IMycSignal, IMycEvent)
TMycEvent = class(TInterfacedObject, TSignal.ISignal, TEvent.IEvent)
strict private
FSubscribers: TMycNotifyList<IMycSubscriber>;
protected
@@ -38,7 +38,7 @@ type
procedure Trigger;
end;
TMycNullEvent = class(TMycNullSignal, IMycEvent)
TMycNullEvent = class(TMycNullSignal, TEvent.IEvent)
private
procedure Trigger;
end;
@@ -47,13 +47,13 @@ type
// It is initialized with a count. Calls to its Notify method (as an IMycSubscriber)
// decrement this count. When the count reaches zero, the latch transitions to the "set"
// state (IsSet becomes true), notifies its current subscribers once, and then remains set.
TMycLatch = class(TInterfacedObject, IMycState, IMycLatch)
TMycLatch = class(TInterfacedObject, TState.IState, TLatch.ILatch)
strict private
FSubscribers: TMycNotifyList<IMycSubscriber>; // List of subscribers waiting for this latch to be set.
private
[volatile]
FCount: Integer; // The internal countdown value for the latch.
function GetState: TState; // Implementation for IMycLatch.GetState and IMycFlag.GetState.
function GetState: TState; // Implementation for TLatch.ILatch.GetState and IFlag.GetState.
protected
function GetIsSet: Boolean;
public
@@ -62,7 +62,7 @@ type
constructor Create(ACount: Integer);
destructor Destroy; override;
// IMycSignal implementation
// ISignal implementation
function Subscribe(Subscriber: IMycSubscriber): Pointer;
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
@@ -72,7 +72,7 @@ type
function Notify: Boolean;
end;
TMycNullLatch = class(TInterfacedObject, IMycLatch)
TMycNullLatch = class(TInterfacedObject, TLatch.ILatch)
private
function GetState: TState;
function Notify: Boolean;
@@ -81,7 +81,7 @@ type
// TMycFlag implements a resettable "dirty flag".
// It can be explicitly set to dirty (via Notify) or reset to clean (via Reset).
// Subscribers are notified of relevant state changes.
TMycFlag = class(TInterfacedObject, IMycState, IMycFlag)
TMycFlag = class(TInterfacedObject, TState.IState, TFlag.IFlag)
strict private
FSubscribers: TMycNotifyList<IMycSubscriber>; // List of subscribers interested in state changes of this dirty flag.
private
@@ -96,7 +96,7 @@ type
destructor Destroy; override;
// Factory method to create a new TMycFlag instance.
class function CreateDirty: IMycFlag; static;
class function CreateDirty: TFlag.IFlag; static;
function Subscribe(Subscriber: IMycSubscriber): Pointer;
procedure Unsubscribe(Tag: TMycNotifyList<IMycSubscriber>.TTag);
@@ -105,11 +105,11 @@ type
// Sets this flag to dirty (true). Notifies subscribers if it transitioned from clean to dirty.
function Notify: Boolean;
// IMycFlag implementation. Resets the flag to clean (false).
// TFlag.IFlag implementation. Resets the flag to clean (false).
function Reset: Boolean;
end;
TMycNullFlag = class(TInterfacedObject, IMycFlag)
TMycNullFlag = class(TInterfacedObject, TFlag.IFlag)
private
function GetState: TState;
function Notify: Boolean;
@@ -250,7 +250,7 @@ end;
function TMycLatch.GetState: TState;
begin
// TMycLatch itself implements IMycState.
// TMycLatch itself implements TState.IState.
Result := Self;
end;
@@ -320,7 +320,7 @@ begin
FSubscribers.Create;
end;
class function TMycFlag.CreateDirty: IMycFlag;
class function TMycFlag.CreateDirty: TFlag.IFlag;
begin
// Factory method to create a new TMycFlag instance.
Result := TMycFlag.Create;
@@ -346,7 +346,7 @@ end;
function TMycFlag.GetState: TState;
begin
// TMycFlag itself implements IMycState.
// TMycFlag itself implements TState.IState.
Result := Self;
end;