Should the business layer return dataset/datatable, or an object/object set?

Source: Internet
Author: User

Today, I saw an article in Si Gui's blog.ArticleThe feeling is the same:

..............................
If your application inherently has no business logic or your application is simple, or your goal is to display the data in the database, use dataset/datatable. Dataset/datatable provides many useful methods (filter/sort /...), In addition, after modifying the backend database, you do not need to modify the intermediate encoding. You can modify the binding encoding of the display layer to reflect the changes.

However, dataset/datatable often reflects the schema in your database. Is the coupling between your performance Layer and your database so strong, it should be a question to consider. But when dataset/datatable is so convenient and flexible, and the coding process is very efficient, why not?

In addition, your application is not only used to display data, but usually needs to edit (Add/modify/delete) data. However, containers such as dataset and datatable provide good functions to help you remember the status of your data. They are very compatible with the unit of work mode in Martin Fowler's peaa book. Then, you can use dataadapter to update the data to the database at a time (although the operation is not a one-time operation.

Then you will operate dataset/able in many places, even if the encoding is a bit repetitive, and you are directly operating on the data, you will feel a little uneasy, but think of the advantages of dataset/datatable, ah, so convenient .... Before you know it, similar operations will be scattered across the logic layer, ah, what domain model, my database-driven programming is also pretty good... When maintenance is required, or when a revision is required, the business logic will be like a splash of time .... Ah, my project is relatively small. Start over again .... If you didn't learn anything here, we will be looking forward to another unmaintainable Project
..............................

Related connections

1. Aaron skonnard talked about the impact of dataset returned from WebService on interoperability.

2. Scott hanselman said that dataset is a bowl, not a fruit, but a strong dataset is a bowl with an apple on it.

3. Karl Seguin pointed out the dataset problem in the article "Mastering ASP. NET Path: Introduction to custom object classes" on msdn.

4. Barry Gervin disagree and lists the advantages of dataset.

5. jelle druyts does not agree, saying dataset is not evil.

6. two articles in the mode and Practice on using dataset as DTO summarize the advantages and disadvantages.
Implementing Data Transfer object in. net with a dataset
Implementing Data Transfer object in. net with a Typed Dataset

I agree with the above points, but it is very convenient to use domain model in the presentation layer programming, but it also makes me feel a headache, good, it's o/R Mapping.

Generally, there are two Domain Models:
1. Each object corresponds to a row in the table in the database. Active record mode
2. There are many objects (because inheritance and mode are used, such as one interface and multiple implementation classes) in the Data mapper Mode

However, I am not so specific. Most projects use the activerecord mode, that is, the petshop mode. The datamapper mode is used when you encounter a difficult location (for example, an email attachment and a document attachment are identical, but they are in two tables .......

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.