Wednesday, August 24, 2005
Presenter
Joanna Carter (TeamB) Nov 23 2004, 6:31 pm hide options
Newsgroups: borland.public.delphi.oodesign
From: "Joanna Carter \(TeamB\)"
Date: Tue, 23 Nov 2004 10:31:41 -0000
Local: Tues, Nov 23 2004 6:31 pm
Subject: Re: Correct design ?
In the business layer of the application. The theory is that it should be possible to write the business logic of an application as if there were no forms or database; so creation, alteration and destruction of BOs happens entirely in the BO layer.
Of course, most applications have a starting UI, but that should really reflect the Application object.
e.g.
TBusinessApplication = class
...
public
procedure BrowseEmployees;
procedure BrowseCustomers;
...
end;
procedure TBusinessApplication.BrowseEmployees;
begin
var
EmployeeList: TObjectCollection; // generic list of TObjectValueTypes
ListPresenter: TListPresenter; // generic UI for choosing objects
Employee: TEmployee;
Presenter: TObjectPresenter; // base class for UI to edit single objects
begin
EmployeeList := TObjectStore.RetrieveCollectionForType(TEmployee);
ListPresenter := TListPresenter.Create(EmployeeList);
Employee := TEmployee(ListPresenter.SelectedItem);
ListPresenter.Free;
Presenter := TEmployeePresenter.Create(Employee);
Presenter.Free;
end;
The application .dpr file would look something like this :
var
BusinessApp: TBusinessApplication;
begin
Application.Initialize;
BusinessApp := TBusinessApplication.Create(Application);
Application.Run;
end.
Passing Application to the BusinessApp is necessary to ensure that it can be passed to the Presenter that will create the Main Form of the app; otherwise that form will never show and the app will appear not to start.
Somewhere on the main form, you will have a button or a menu item that will call the methods of TBusinessApplication like BrowseEmployees
Newsgroups: borland.public.delphi.oodesign
From: "Joanna Carter \(TeamB\)"
Date: Tue, 23 Nov 2004 10:31:41 -0000
Local: Tues, Nov 23 2004 6:31 pm
Subject: Re: Correct design ?
In the business layer of the application. The theory is that it should be possible to write the business logic of an application as if there were no forms or database; so creation, alteration and destruction of BOs happens entirely in the BO layer.
Of course, most applications have a starting UI, but that should really reflect the Application object.
e.g.
TBusinessApplication = class
...
public
procedure BrowseEmployees;
procedure BrowseCustomers;
...
end;
procedure TBusinessApplication.BrowseEmployees;
begin
var
EmployeeList: TObjectCollection; // generic list of TObjectValueTypes
ListPresenter: TListPresenter; // generic UI for choosing objects
Employee: TEmployee;
Presenter: TObjectPresenter; // base class for UI to edit single objects
begin
EmployeeList := TObjectStore.RetrieveCollectionForType(TEmployee);
ListPresenter := TListPresenter.Create(EmployeeList);
Employee := TEmployee(ListPresenter.SelectedItem);
ListPresenter.Free;
Presenter := TEmployeePresenter.Create(Employee);
Presenter.Free;
end;
The application .dpr file would look something like this :
var
BusinessApp: TBusinessApplication;
begin
Application.Initialize;
BusinessApp := TBusinessApplication.Create(Application);
Application.Run;
end.
Passing Application to the BusinessApp is necessary to ensure that it can be passed to the Presenter that will create the Main Form of the app; otherwise that form will never show and the app will appear not to start.
Somewhere on the main form, you will have a button or a menu item that will call the methods of TBusinessApplication like BrowseEmployees