Database application using MVC paradigm
Asked Answered
H

2

7

In classic Delphi database application we have a form, a set of data-aware visual controls connected to TDataSets via TDataSources. If one wants to design database application using MVC model, where to place TDataSet components? Should they stay on form and therefore be a part of View? Or should they be encapsulated inside some Model object? If the latter how they could be bound to visual components?

Handwoven answered 11/4, 2010 at 8:12 Comment(0)
F
3

You could see delphi project via MVC eyes like this:

TDataModule -> Model
TYourForm.pas -> Controller
TYourForm.dfm -> View

If you accept it, than you should put DataSets in Datamodule.

In project I am working on, I also put TClientDataSets on forms and clone data on creation. That way I have isolated data in TForm, with logic in datamodule.

Pity there is no ActiveRecord like framework for delphi.

Fellows answered 11/4, 2010 at 8:44 Comment(1)
+1 Indeed; Delphi has done MVC for soo long, that people forget it does :-)Alabaster
O
2

I have made a MVC-like framework for my current customer, for you it would make something like this:

  • TDatamodule = Model (for data, so TDataset stuff)
  • TForm = View (contains datasources, connected to TDatasets of model)
  • Controller.pas = Controller (execution/business logic)

Try to keep your form as clean as possible: may only contain stuff for GUI. Implement special (business rules, data updates etc) logic in controller. Keep in mind: your view must be easily be replaced with another view (like webpage).

In my MVC-like framework, the view calls methods (like search, refresh, etc) with params of the controller, the controller knows what and how to search etc and fills/updates the model. View is connected with the model (property of controller).
It is not exactly MVC, but this way the GUI is separated from all kind of logic and it is still easy to debug and maintain (you could use dependency injection/loose coupling with the controller etc but this makes it more difficult, only use when needed)

Orchestrion answered 12/4, 2010 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.