Skip to content

Instantly share code, notes, and snippets.

@ortuagustin
Last active December 5, 2016 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ortuagustin/3b14d51881b922cdc500f214dc85e36a to your computer and use it in GitHub Desktop.
Save ortuagustin/3b14d51881b922cdc500f214dc85e36a to your computer and use it in GitHub Desktop.
IFoo = interface
['{4061C455-B122-48D6-940F-9C1B2FD4A689}']
end;
IDoesntWorkFactory = interface
['{E9A093ED-C429-46C3-82DD-D5D32EB9120F}']
function Create(const Blabla: string): IFoo; overload;
function Create(const Blabla: Integer): IFoo; overload;
end;
IWorkingFactory = interface
['{E32C2F49-F6E4-4D7F-B1DF-787C3CC55A39}']
function Create(const Blabla: string): IFoo;
end;
TWorkingFactoryImpl = class(TInterfacedObject, IWorkingFactory)
strict private
function IWorkingFactory.Create = FooCreate;
function FooCreate(const Blabla: string): IFoo;
end;
TDoesntWorkFactoryImpl = class(TInterfacedObject, IDoesntWorkFactory)
strict private
function IDoesntWorkFactory.Create = FooCreate;
function IDoesntWorkFactory.Create = FooCreate; // identifier redeclared
function FooCreate(const Blabla: string): IFoo; overload;
function FooCreate(const Blabla: Integer): IFoo; overload;
end;
@ortuagustin
Copy link
Author

ortuagustin commented Dec 5, 2016

This doesn't work aswel:

  TDoesntWorkFactoryImpl = class(TInterfacedObject, IDoesntWorkFactory)
  strict private
    function IDoesntWorkFactory.Create = FooCreateString;
    function IDoesntWorkFactory.Create = FooCreateInteger; // identifier redeclared
    function FooCreateString(const Blabla: string): IFoo;
    function FooCreateInteger(const Blabla: Integer): IFoo;
  end;

"Not so ideal" method name 'Create' isn't the problem either

  IDoesntWorkFactory = interface
    ['{E9A093ED-C429-46C3-82DD-D5D32EB9120F}']
    function DoIt(const Blabla: string): IFoo; overload;
    function DoIt(const Blabla: Integer): IFoo; overload;
  end;

  TDoesntWorkFactoryImpl = class(TInterfacedObject, IDoesntWorkFactory)
  strict private
    function IDoesntWorkFactory.DoIt= DoItString;
    function IDoesntWorkFactory.DoIt= DoItStringInteger; // identifier redeclared
    function DoItString(const Blabla: string): IFoo;
    function DoItStringInteger(const Blabla: Integer): IFoo;
  end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment