Delphi implementation interface and business logic separation

xiaoxiao2021-03-06  63

Delphi implementation interface and business logic separation

J Snow (Zhuam )ndeveloper@sina.com

Before doing Delphi software development, I was engaged in the development of Java software. From Java Open Source Community, I learned a lot of software design ideals. This may be my return from Java! Open your eyes!

The nearest project was developed with delphi, so I looked at Delphi. I looked at the Delphi book in a month. When I did a Delphi, I used Delphi's grammar, Java's ideological To develop and design software, it feels a bit tired! Ah, gossip less, go to the topic!

Delphi is a quick software development IDE. The usual Programmer is a first-drawing view (interface), then writes Source Code in the corresponding event, see example:

1. For example, I want to insert a record into the database, usually the case is this!

SQL EXAMPLE: INSERT ?? INTO ?? EXAMPLETABLE1 (Field1, Field2, Field3) Values ​​(Values1, Values2, VALUES3)

Now suppose this Delphi form has three Text controls, Name is Frist, Second, Three, respectively.

Below I use three different ways to insert the data into the database:

1, plug directly into the client ----------> Database

INSERT ?? INTO? EXAMPLETABLE1 (Field1, Field2, Field3) Values ​​(Frist.Text, Second.Text, Three.Text)

2, indirect insertion? Client --- (Text Pass) ---> Dataclass -------> Database

It means to save the form data into a data class, then take data from this data class to the database from this data class.

Note: Form controls are stored directly into the data class directly through Text. This Dataclass is just used to store data status, which is all in the property, no business logic!

As follows: {------------------------------------------- Author: Zhuam Date: Class Property: All AssociatorRunBean Information Set Mothed Descripte: Save the membership information, -------------------- --------------------------} TYPE TASSOCIATORRUNBEAN = Class (TOBJECT) Private fkilometre: double; fcarnumber: string; fnumber17: string; fcarcolor: String ; FAssociatorID: string; FCarCapacity: string; FFrameNumber: string; FEngineNumber: string; FAvailabilityDate: tDate; FRegisterDate: tDate; FBackPicture: TImage; FFrontPicture: TImage; FLeftPicture: TImage; FRightPicture: TImage; function getBackPicture: TImage; function getFrontPicture: TImage ; function getLeftPicture: TImage; function getRightPicture: TImage; procedure setAssociatorID (const Value: string); procedure setAvailabilityDate (const Value: tDate); procedure setBackPicture (const Value: TImage); procedure setCarCapacity (const Value: string); procedure setCarColor ( Const value: string; procedure setcarnumber (const value: string); Procedure Seten gineNumber (const Value: string); procedure setFrameNumber (const Value: string); procedure setFrontPicture (const Value: TImage); procedure setKiloMetre (const Value: Double); procedure setLeftPicture (const Value: TImage); procedure setNumber17 (const Value: string); procedure setRegisterDate (const Value: tDate); procedure setRightPicture (const Value: TImage); public constructor create; destructor destroy; override; property AssociatorID:? string read FAssociatorID write setAssociatorID; ??? // membership number property CarNumber? : String read fcarnumber write setcarnumber; ???????????? // license plate number Property? carcolor: string read fcarcolor write setcarcolor; ??????????????? // Car Color Property? Carmode: String Read Fcarcolor Write SetCarcolor;

??????????????????/ model proty? Enginenumber: String Read Fenginenumber Write setEnginenumber; ??? // Engine number Property? Framenumber: String Read FFramenumber Write setframenumber; ???? ?? // frame number Property? Carcapacity: String read fcarcapacity Write setCarcapacity; ?????? // Displacement Property? Number17: String Read Fnumber17 Write setNumber17; ????????????? ?? // 17-bit protroperty? Kilometre: Double Read fkilometre Write setkilometre; ???????????? // kilometer number proty? RegisterDate: tdate read freigisterDate Write SetRegisterDate; ???? // Register ? date property AvailabilityDate: tDate read FAvailabilityDate write setAvailabilityDate; // effective date property FrontPicture:? TImage read getFrontPicture write setFrontPicture; property BackPicture:? TImage read getBackPicture write setBackPicture; property LeftPicture:? TImage read getLeftPicture write setLeftPicture; property RightPicture:? TImage Read GetrightPicture Write SETRIGHTPICTURE; END;

INSERT INTO EXAMPLETABLE1 (FIELD1, FIELD2, FIELD3) VALUES (AssociatorRunbean.frist, AssociatorRunbean.text)

3, indirectly insert? Client? --- (Custom Property Pass) --->? Dataclass ------->? Database

It means to save the form data into a data class, then take data from this data class to the database from this data class.

Note: The form control is to store data into the DataClass data class directly. This Dataclass is just used to store data status, which is all in the property, no business logic!

INSERT ?? INTO ?? Exampletable1 (Field1, Field2, Field3) Values ​​(AssociatorRunbean.frist, AssociatorRunbean.text)

Someone will ask me here, what is the meaning of this! The careful comrades may have been noticed! This is a means that completes the separation of the Delphi interface and business logic.

转载请注明原文地址:https://www.9cbs.com/read-119198.html

New Post(0)