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?
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.
I have made a MVC-like framework for my current customer, for you it would make something like this:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With