Should I use a class or method to transfer a dynamic remote procedure call?

Situation

I would like to make the RPC interface easier to use. This is a customizable interface, so there is no wrapper available.

I need to write some wrappers around functions, which often have many arguments.

Possible solutions

Solution 1 - Using a class for each function:

TDoSomethingFunction = class
public
  property Arg1: Integer;
  property Arg2: string;
  property Arg3: Boolean;
  procedure Run;
end;

The caller must create an object to call the function:

var
  DoSomething: TDoSomethingFunction;
begin
  DoSomething := TDoSomethingFunction.Create;
  try
    DoSomething.Arg1 := 0;
    ...
    DoSomething.Run;
  finally
  free;
end;

Method 2 - using the wrapper method for each function:

procedure TRPCInterface.DoSomething(AArg1: Integer; AArg2: string; AArg3: Boolean);

The caller can simply call him:

TRPCInterface.DoSomething(0, ...);

Pro and contra

Method 1 - a class for each function

Contra

  • More code required.
  • An object must be created that takes up memory.

Pro

  • Reading the code is simpler, you do not need to look for an ad to find out what arguments are.

Method 2 - Wrap Method

Contra

  • , , .

Pro

  • .
  • ( ).

?

+5
2

, -, .

TDoSomethingArgs = class
public
  property Arg1: Integer;
  property Arg2: string;
  property Arg3: Boolean;
end;

procedure TRPCInterface.DoSomething(Args: TDoSomethingArgs);

, , . ( ) , ( , ), , - .

+2

Delphi, , :

type
  TArgList = class( TDictionary< String, Variant > );

type
  TBaseFunc = class
  private
    FArgs: TArgList;
  public
    function Run: Boolean; virtual; abstract;
  public
    property Args: TVarList read FArgs write FArgs;
  end;

type
  TSpecialFunc = class( TBaseFunc )
  public
    function Run: Boolean; override;
  end;

function TSpecialFunc.Run: Boolean;
begin
  // here where you can access args as variants
end;

:

ASpecialFunc.Args.AddOrSetValue('ArgumentName', 2012);

, IMHO .

: , , .

, , (:

+2

All Articles