ADO Database Delphi

Title: Separate Business Logic from Data Access
Question: How to separate business logic from data access?
Answer:
Separating Business Logic from Data Access has many good advantages.The first advantage is less work to do. By putting data access into repository datamodules, we don't have to configure data access in each datamodule, we just pick it from repositories and put it on datamodules on runtime. Any changes on data access only need to be done in repositories and the changes will be reflected in datamodules. Second advantage is flexibility. All specific job about data access had already done in repositories. Datamodules have only general view on these repositories. By doing this we can replace the repositories from one database server to another or one data access component to another. So our development wont be tied into single solution or single product (but tied to Delphi of course ^_^). Third advantage is scalability. We can develop an application that can switch easily between two tier and three tier architecture.
The Solution
Our database control must be able to link to dataset descendants in repositories in design time but linked to dataset descendants in a specified datamodule on runtime. First there must be a mechanism on imitating dataset descendants on repositories. Or in my term: brokering the dataset. So I create a component named TDatasetBroker this component is located in datamodule and representing a dataset descendant in repository. The problem is I cant write even a single line of specific data access statement in this component, because our datamodule will not be independent anymore. So I create an abstract component TDatasetBrokerModel for defining the general method for brokering dataset. So when I need to implement this on a TDataset descendant I will create a new component inherited from TDatasetBrokerModel and implement all needed method. For example I will create TQueryBrokerModel for TQuery component. Each TDatasetBroker in datamodule is linked into a TDatasetBrokerModel which in this example is TQueryBrokerModel. So the first problem is solved. The second problem is all references to dataset descendants in repository must be redirected into dataset descendants in our datamodule. Because we cant do this directly in TDatasetBroker, so this must be defined in TDatasetBrokerModel and implemented in TQueryBrokerModel and used by TDatasetBroker. By now all database controls will refer to the datamodules dataset descendant. This solution works fine for you until someday there is cheap and powerful dataset descendant component TXQuery. What you need to do is build TXQueryBrokerModel and start creating the repositories which have the same name but different implementation from your TQuery repository. After finished building the repositories you can unplug your old repositories and plug your new repositories into your application. So how about specific methods or attributes you need but not defined in TDatasetBrokerModel. You can create an abstract component TCustomDatasetBrokerModel and define your methods or attributes as you need. From now on all your DatasetBrokerModels will be derived from TCustomDatasetBrokerModel. You also may inherit new component from TDatasetBroker that utilizes your TCustomDatasetBrokerModel.
Until now this solution works fine for two tier application because all TDataset descendant still use database connection in repository. This wont work in three tier application because each remote datamodule should have its own database connection. I think you can guess what is my solution ^_^. Yup youre right TConnectionBroker for representing database connection from repository and TConnectionBrokerModel descendant for doing dirty work with specific data access implementation. I have a working example on this proposal so this is not a wild dream in a daylight. This proposal is still in early stage so I welcome every critics, suggestion or advise. Thank you.
You may download the component (dcu) and the sample application (source code) on the link above (thank you to delphi3000). I also give the bitmap for each component in dcr file. Please don't mind to join DatasetBroker you can have access to newest version components there and may post questions there.
I have implementations for BDE and ADO plus the Demo Project for both repositories at DatasetBroker group.
http://groups.yahoo.com/group/datasetbroker