How to implement a parameterized method in an interface for using in the Spring Framework

StackOverflow https://stackoverflow.com/questions/10452181

  •  05-06-2021
  •  | 
  •  

Вопрос

I am trying to integrate the Aurelius ORM framework and the Spring 4D framework and I am for the most part succeding, however the Aurelius ORM (and others too) rely on an "Object Manager" for the loading and saving of objects in the database. Part of the work I am doing is trying to separate as much as I can the implementation and the interfaces of the classes. When creating the interface for this Object Manager (TObjectManager in Aurelius) however, I am having difficulty implementhing the "Find" method of the Object Manager. For example, the object manager supports the following methods:

MyObjectManager := TObjectManager.Create(Connection);
ExistingSale := MyObjectManager.Find<TSale>(1); // Find the Sale record with ID = 1 of the class TSale.

Now trying to convert the ObjectManager declaration to an interface Im trying to do it the following way:

IObjectManager = Interface
     ['{1F54162B-D7D7-4E42-AC9D-D269803371DB}']
     function Find<T>(ID: Integer) : T;
end;

And this is where there is the problem, because the compiler fails with the error:

[DCC Error] E2535 Interface methods must not have parameterized methods

Basically I need to come up with an interface function that I could call in my own Object Manager, for example:

function TMyOwnObjectManager.Find<T>(ID: Integer) : T;
begin
     Result:=fAureliusObjectManager.Find<T>(ID);
end;

Thanks anyone for your help, been trying to come up with a soultion for several days now.

Это было полезно?

Решение

Ok, although not the solution I was looking for in regards to the declaration of the interface, I managed to overcome the problem inheriting from the TObjectManager and re-declaring the Find function the following way:

function TMyOwnManager.Find(Class: TClass; IdValue: Variant): TObject; 
begin 
    // Call the TObjectManager protected method "Find(Clazz:TClass; IdValue: Variant)" 
    Result := inherited Find(TClass(Class), IdValue); 
end;

Hope it helps someone.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top