What is the name of this design pattern?

I often find that I am writing classes that are used as follows:

  • Create a class object
  • Calling some Run or Run methods for this object
  • Destroy object

This adds some overhead to the calling code, for example:

var
  Foo: TFoo;
begin
  Foo := TFoo.Create(...);
  try
    Foo.Run(...);
  finally
    Foo.Free;
  end;
end;

It really can be written much shorter than:

begin
  TFoo.Run(...);
end;

In this case, the unit containing the class TFoowill look like this:

type
  TFoo = class
  private
    FBar: TBar;
    procedure InternalRun;
  public
    class procedure Run(ABar: TBar); static;
  end;

class procedure TFoo.Run(ABar: TBar);
var
  Foo: TFoo;
begin
  Foo := TFoo.Create;
  try
    Foo.FBar := ABar;
    Foo.InternalRun;
  finally
    Foo.Free;
  end;
end;

Overhead is moved from the calling code to the class TFoo.

What is the name of this design pattern?

+4
source share
2 answers
+3
+2

All Articles