Net region domain model (1)

Source: Internet
Author: User
The domain model opens another window Garden of OO to discuss so much about Oo, so let's get together.


The most important idea of object-oriented development is to simulate the real world.


However, in a large number of systems that use object-oriented language development, it is difficult for you to see this simulation, but it is still some database-centric addition, deletion, modification, and query actions, rarely seen" the real world.


This situation is largely affected by the database center.


Database-centered system development has a mature set of theories and has been tested for many years. This is the best choice for most information systems so far.


Taking a book management system as an example, there are some features: new books are shelved, borrowed, and returned.


According to the database method, we will design three relationships ﹕

Books (bookid, ISBN, title, author, publisher, Content Overview)

Library certificate (cardid, name, phone number, ID card number, address)

Borrow (bookid, cardid, borrow time, return time ,)


Then create a table in the database


Next we will provide the man-machine interface for adding, deleting, modifying, querying, adding, deleting, modifying, and querying books, borrowing, and returning books.


Then write the add, delete, modify, and query objects and Methods around the database. The book. Save and bookmanager. Save methods are also discussed here. In fact, as long as the code is not repeated, it is convenient to use, efficient, and unified, no matter where the Save method is put, it is justified.


For most information systems, database-centric is very suitable. This method is also very efficient and mature.


However, you can try another method.


We imagine the following scenario ﹕


There is a [library]

There are many [bookshelves] in the [library] (which can be understood as: Books category directory)

There are many [books] on [bookshelves]

A reader enters the system to help him browse the [bookshelves] of the [library]. then, find the [Book] He wants to borrow in one of the [bookshelves]. Next, it will hand over the [borrow certificate] to the Administrator and ask the [Book] to be borrowed. The Administrator will go through the borrowing procedures ﹐ generate a [borrow Record] to complete the lending process


This scenario can be completed by the following object:


Class Library helper

{



Public list <bookshelves> All bookshelves

{

Return library. instance. All bookshelves

}



Public void: select the bookshelf)

{

Record current bookshelf

}



Public void: select books)

{

Record selected books
}



Public void borrow (borrow a Certificate)

{

If (borrow certificate. Borrow record! = NULL)

Throw exception "the book has been lent out ";

New borrow record ();

Borrow record. Book = current book

Borrow record. Card = debit card

Borrow record. Time = now

Current book. Lending record = lending record

Borrowing record. Add (borrowing record)

}

}



This is the use case implementation of books, and these objects are the objects in the system domain model.

There is no database, no UI, and only business and logic.



When you develop a human-machine interface, you can select windows or web to use this class (display the bookshelf, select a book, display the books on the shelf, select a book, and borrow the button) the borrowing function is completed.



From beginning to end, we did not see databases in our design.



Our system as a real-world model is sufficient. when mounting a new book, you only need to add it to the bookshelf to apply for a new credential, similarly, when you return a book, you only need to cancel the association between the lending record and the book.



However, this ideal environment does not exist, so that we have the concept of object persistence. As a stable and efficient persistent solution, the database is a good choice (I have tried all objects are backed up to the hard disk at intervals in the form of binary files ).



As for how to convert the objects in the system to the tables in the database, Orm began to come in handy.

However, please remember that when using data inventory objects, do not be coupled with the domain model (do not use a book in the borrowing method. insert code: Our domain objects are only related to each other, but not to the database. Our database stores the objects in the current system and their statuses) design Patterns, AOP. It's time for them to show their skills.



(By the way, I have always thought that the database-centric and ORM-based system design scheme can be very frustrating, so you have to add, delete, modify, and query the SQL statements ﹐ you can't connect to the database, just plug in the O/R Mapping, so that very powerful SQL, it's strange to turn it into a clumsy object method .)



In fact, the database-centric categories and tools provided by Microsoft in the Net Framework are very powerful, such as ADO. net, dataset, the typed dataadapter is automatically generated, and the front-end gridview control is suitable for developing information systems. I will directly use most simple systems. However, when C # provides you with such a perfect how can you not try the real object-oriented development?
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.