Content-Length: 286319 | pFad | http://github.com/JavierusTk/command-delphi

C2 GitHub - JavierusTk/command-delphi: Command pattern for Delphi (IComand & TComand)
Skip to content

Command pattern for Delphi (IComand & TComand)

License

Notifications You must be signed in to change notification settings

JavierusTk/command-delphi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Pattern for Delphi

 Delphi Support

Overview

Simplified version of the GoF Command Pattern, created for the purposes of modernization of VCL projects. Also added action factory to this project, which is wrapping a command into VCL action.

The Command Pattern

Implementation

The project contains two versions of the pattern implementation:

  1. classic Gang of Four ICommand interface
  2. VCL TCommand class based on TComponent

Modernization process

The TCommand component was created to help the modernization of the legacy VCL code. It assists the extraction of tangled code, which after securing it with unit tests, can be refactored into cleaner and cheaper to maintain object-oriented code.

TCommand component is a transition object that should be refactored after clearing extracted code and after removing UI dependencies

TCommand component

The easiest way to use the TCommand component is to create a new class, paste long method into Execute method and add all dependencies as properties to published section. See sample bellow.

Created object you can wrap into TCommandAction object and use it as classic VCL action. You can use the factory for this task (described below)

Diagram of TCommand usage in the VCL application:

VCL TCommand factory

Methods of the class TCommandVclFactory:

  1. function CreateCommand - creates a single command component (TCommand descendant) and inject dependencies into it
  2. procedure ExecuteCommand - executes a command (creates a command, injects dependencies executes it and removes)
  3. function CreateCommandAction - creates TAction, which contains embedded TCommand and injects dependencies

Samples

Creates command and inject dependencies:

ACommand := TCommandVclFactory.CreateCommand<TButon2Command>(
    AOwner, [Memo1, Edit1]);

Creates command, inject dependencies, execute it and remove:

TCommandVclFactory.ExecuteCommand<TButon2Command>(
    [Memo1, Edit1]);

Create TCommandAction and command with injection:

act := TCommandVclFactory.CreateCommandAction
    <TButon1Command>(Self, 'Run command: Button1',
    [Memo1]);
Button1.Action := act;

Sample TCommand component:

type
  TButon2Command = class (TCommand)
  private
    FMemo: TMemo;
    FEdit: TEdit;
  protected
    procedure Guard; override;
  public
    procedure Execute; override;
  published
    property Memo: TMemo read FMemo write FMemo;
    property Edit: TEdit read FEdit write FEdit;
  end;

procedure TButon2Command.Guard; override;
begin
  Assert(Memo<>nil);
  Assert(Edit<>nil);
end;

procedure TButon2Command.Execute;
begin
  inherited;
  Memo.Lines.Add('');
  Memo.Lines.Add('Getting Edit text and put it here ...');
  Memo.Lines.Add('  * Edit.Text: '+Edit.Text);
end;

About

Command pattern for Delphi (IComand & TComand)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Pascal 99.0%
  • Batchfile 1.0%








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/JavierusTk/command-delphi

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy