Skip to content

New Rule: Class method should not be invoked from an object instance #303

Open
@Skarvion

Description

@Skarvion

Prerequisites

  • This rule has not already been suggested.
  • This should be a new rule, not an improvement to an existing rule.
  • This rule would be generally useful, not specific to my code or setup.

Suggested rule title

Class method should not be invoked from an object instance

Rule description

Calling a class method from an object instance would mislead reader that the method is an object method and may affect the object itself. Call class method using class name as prefix.

Rationale

// class declaration and implemeantion
type
  TFoo = class(TObject)
  public
    class procedure Bar;
  end;

implementation

class procedure TFoo.Bar;
begin
  // do something
end;

// calling
var
  FooObj: TFoo;
begin
  FooObj := TFoo.Create;
  FooObj.Bar; // non-compliant

  TFoo.Bar; // compliant
end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestruleImprovements or additions to rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions