Any suggestions on sharing data access, business logic and GUI in Delphi

I want to separate the data layer from business logic and business logic from the graphical interface. Plunging into the web, I came across several resources, but still could not understand my mind. Some people talk about patterns, which some others point to different frames. My requirements:

  • manage data from rdbms (mainly mysql) CRUD operations
  • related to id generation (whether to use auto increment or provided data engine or generated pascal code)
  • table relations can be logical (referential integrity is not used) or not
  • the need for the ability to generate relationships of objects from a data model
  • Data must be converted to a business object and managed business logic.
  • Use existing gui or freeware components.

What I need:

  • some guidelines / suggestions with a basic example of application code / layout (e.g. modules-classes-modules-directories) ... Not being an expert in OOP, I get confused when I have to create a class hierarchy
  • simple structure with a textbook
  • or even your own daily code / framework / approach
+6
user-interface orm delphi business-objects business-logic-layer
source share
7 answers

Since you are using Delphi, make sure you look at DataModules. Here you place the database access components and logic.

Put the classes in simple "Unit" files.

Make a conversation with these two people so that everything happens. You can directly use the database access components, but this is best used as a "display only" mode and use the datamodule to perform data operations. (You can do everything in the form for basic applications, but if you want a modular application, keeping it separate, is reasonable).

+11
source share

One easy way to enforce this kind of separation is to write unit tests for your business logic. In addition to other (significant) advantages, doing code verification means that it cannot (intentionally or otherwise) be closely related to the user interface.

I try (but not always succeed) to save the details of the data layer separately using ClientDataSets, regardless of what is used at the end (usually DBExpress or DBISAM). I also try to write at least some integration tests to make sure that the data layer is working as expected (a separate test database with known values).

With business logic and data (even partially), the user interface is much more straightforward. And supported.

+4
source share

Take a look at tiOPF

+3
source share

Personally, I use tiopf for the business model. Tiopf provides a layer of data access. The latest code from the repository includes a model-gui-mediator framework similar to MVC for displaying a model. This allows you to display your data using standard delphi components.

Tiopf also includes a number of identifier generators (guides, 32-bit and 64-bit integers, etc.).

If you are interested in tiopf, I suggest you start by looking at overview . Then forward any questions to the newsgroups.

+3
source share

Try your hand at open source InstantObjects , and you'll always want to use it for all types of database programming in Delphi.

In IO, you will need to define the entire data structure in your interface, and then you will create the necessary code for you.

Just try it.

Regarding the trust generation id generation MySQL for generating an auto increment id for yours. Do not waste time coding it.

+2
source share

The method that I use and which works very well is to try to take on different roles in your application, and then program as if you were in that role. For example, when you work with a database, do not even think about the graphical interface. Instead, consider providing classes and methods that simply work with data. If you create your own SDK, which you will use later, you will find that its maintenance will be much easier.

Test-based development is your friend. Get to know DUnit and create small, concise tests to run any nontrivial code. Document interfaces and everything that is not visible when looking at a screen full of code.

+2
source share

I would look at Model-View-Controller (which is an extension of the Observer / Observable Pattern). This means that the β€œview” (that is, the user interface) only knows how to update the data and then respond to the updated data. A model (or Observable) knows how to manipulate data and tell Views that it is updated. This means that you can replace the user interface without changing the data provider, and vice versa.

Do a search on Google, as there are a lot of examples for Delphi (but not for Java / C #, etc.)

+1
source share

All Articles