View的"中介者"或"观察者"--Presenter
unit IWA.Presenter.LoginPresenterImpl;
interface
uses IWA.View.LoginViewIntf, IWA.DTO.LoginDTOIntf, IWA.Model.LoginModelIntf;
type
TMainPresenter = class
private
FView: ILoginView;
FModel: ILoginModel;
function MakeDTO: ILoginDTO;
procedure OnViewSubmit;
protected
public
procedure AfterConstruction; override;
constructor Create(AView: ILoginView; AModel: ILoginModel);
end;
implementation
uses IWA.DTO.LoginDTOImpl;
{ TLoginPresenter }
procedure TLoginPresenter.AfterConstruction;
begin
inherited;
FView.OnSubmit := OnViewSubmit;
end;
constructor TLoginPresenter.Create(AView: ILoginView; AModel: ILoginModel);
begin
inherited Create;
FView := AView;
FModel := AModel;
end;
function TLoginPresenter.MakeDTO: ILoginDTO;
begin
Result := TLoginDTO.Create;
Result.UserID := FView.UserID;
Result.UserPassword := FView.UserPassword;
end;
procedure TLoginPresenter.OnViewSubmit;
var
DTO: ILoginDTO;
begin
DTO := MakeDTO;
FModel.CheckLoginInfo(DTO);
FView.UserName := DTO.UserName;
end;
end.