Implement DDD hierarchy

Source: Internet
Author: User

When developing enterprise-level business systems, our preferred solution is domain logic.+Object relationship table ing. What is an enterprise-level business system? First, the logic is relatively complex for specific fields. Second, there are many non-technical reasons for data persistence. Generally, relational databases are used. Third, there are some workflows and rich user interactions.

When we select layers, our preferred solution is also the one we mentioned earlier.DddLayered.UILayer->Domain Layer->Infrastructure layer. It is such a division on the logic layer, but physicallyCodeYou must pay attention to the layout.

First, let's talk about the core logic layer, which naturally requires at least oneProgramA general application of an assembly is enough. There is also a domain service layer in the hierarchy, which can also be placed in this Assembly. You can define both a domain model and a workflow.

Second, how to organize the infrastructure layer. What does the infrastructure layer do? It provides technical support for the implementation of upper-layer domain logic and workflows. Interaction with physical disks (readXMLFile, access the database), and interact with the external system (call the external system'sWebService, The specific technical implementation code for sending emails. However, one of the main infrastructure categories is special, that is, the interaction with relational databases, that is, the database access layer that we often refer. In general, the object relational table Er (for exampleNhiberate). At least one assembly should be proposed for this part. The remaining infrastructure can be put into another procedural set.

Third, with Domain Models, business flows, and specific technologies supporting these logical operations, how can we combine these things? The application service layer serves this purpose. A separate assembly is required here. The role of the application service layer is the domain model. The business flow is combined with the underlying support technology to provideUIOperations provide a clear, large-GranularityAPI. This method is very effective in actual development, which greatly reducesUICoupled with the business logicUILayer-specific calling of clear application servicesAPIIn addition, you can let him focus on his own display logic, this isUIResponsibilities of the layer. For the application service layer, I highly respect the master (I read their books and correctly understand what is System Design). This layer is a very simple layer. However, I don't know this. Although the business contained in this layer is simple from the perspective of business in the field, it is very important for him to organize an operational process and an operational unit.

Fourth,UILayer. This layer must also require at least one assembly. Mainly responsible for implementationUIDisplay logic. First, pay attention to the use of custom controls and custom components. Custom Controls and widgetsUIThe basis for layer encapsulation and reuse. I have also taken some detours by myself, from using custom controls, to using as much as possible, and to distinguishing what kindUIThe logic should be encapsulated into custom controls and the granularity of encapsulation. The user-defined controls are also easy to use and are not easy to use. Later, I found the reasons why I felt that they were not easy to use and made improvements, which were particularly useful.

Why am IUIHow much space does the layer spend? This is the most confusing place for normal development. Because for developers who have just started programming and less experience,UIThe layer is too easy to be mixed with business logic. This will lead to the disadvantages of easy logic confusion, code duplication, and poor reusability. This layer is also the biggest obstacle I have encountered when I promote this architecture in my company. I also continue to sum up my experience in practical use.

In short, do a good jobUILayer, I feel that there are two points to grasp. First, do not confuse the business logic, just let it be responsibleUIDisplay. In this regard, if you replace the current interface with the command line interface, do you need to repeat some code? If you need to repeat some code, we need to consider referring the code to the application service layer or domain logic layer. Second, let the Customer Code call theseUIOr the dialog box can be called in a logical way, regardless of the specificUI.UIThe encapsulation is good. For example, in the drop-down box of a role list, I may inheritComboBoxAnd then add two methods and one attribute,Showallroles (), showroles (icollection <role> proles), selectrole {Get; Set ;},In this way, useUIThe customer code is using thisUIYou don't have to worry about this.UIYou only need to knowUIYou can do whatever you want. Although this is true, there are many specific problems in actual development.

Fifth, the main application defines the main form and menu here. In a large business system, menus cannot be used directly.IDEIn addition, there will be a lot of code for the main form, and some permissions are not easy to control. There are also login forms, and the implementation of the entire systemApplication.

Sixth, the last one is the system'sFramwork. Some interfaces will be defined, and there will certainly beIapplication.Word,Excel,ArcMapIn other large systemsApplicationIt is a global variable of the entire system and a main interface throughout the lifecycle of the business system. This interface defines the progress interface, the status of the current system, and other information. The code that implements these interfaces will be included in the Firestone Application Service in the main application. Because there is some information to passIapplicationTransmits data to the infrastructure layer, domain layer, or other layers. However, some implementations, such as displaying the progress of the current process, need to rely on the implementation of the main form to be implemented in the main application. This is a good embodiment of the separation of interfaces and implementations. The two good coupling solutions we mentioned earlier are interfaces and implementation separation (Arcengine), And the other is events.

Seventh, there may be some temporary general code in the system, maybe the code is extracted into general in this project, and it has not been summarized into the company's public library yet, you may need such a common assembly. When the project ends or is idle, you need to consider extracting the code into the company's Public Library.

 

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.