I have a framework that I developed with several classes and components. I would like to create a main object with access to the entire framework so that all developers can access the methods from a single location.
Example:
MyApp.Framework.DataBase
MyApp.Framework.DateUtils
MyApp.Framework.Users
MyApp.Framework.System
The object MyApp maps entire framework and all developers have full access at any time.
The main question is to create a structure that is robust and easy to expand. After a while I would include a structure of functions and methods of the products of our company.
Example:
MyApp.Blog. (functions about Blog product)
MyApp.WebDocs. (functions WebDocs product)
More example about class:
TMyAppBase = Class
Private
Function GetDatabase: TDataBaseClass;
Function GetUsers: TSystemUsersClass;
Function GetForms: TFormManager;
Public
Constructor Create; Virtual;
Destructor Destroy; Override;
Property Database: TDataBaseClass Read GetDatabase;
Property Users: TSystemUsersClass Read GetUsuarios;
Property Forms: TFormManager Read GetForms;
End;
Using this class:
var
LMyApp: TMyAppBase
begin
ShowMessage(LMyApp.Users.ActiveUserName);
end;
Would that be friends, I would like if possible ideas from yours. My intention its create a single and expansive structure.
As I’ve already wrote in my comment, I think in this case it is a good idea to use one main Service (main class, singleton) wich can provide you access to other services. All your modules have unique ID (
TGUID). At the beginning of program execution they should register themselves in main service.for example. main service unit:
here
class constructor&destructorsimply creates and freesFServicesDictionary.QueryServicemethod returns Service by its unique ID:Method
RegisterServiceextractsRTTIAttribute (ServciceIDAttribute) from parameter’s class name and adds this pair (id-service) to dictionary:now, about end-services. For example UserManager unit:
now we can test our code:
summary:
TAppServicesis the main object, wich provides access to any service in App. It knows nothing about end-services, so it has no dependencies. you can change its implementation as you wish.You may have as many TCustomAppService class descendants as you need. When you add new service to application, you shouldn’t change
TAppServicesclass interface or implementation.