This article from: http://www.cnblogs.com/zhaojunqi/archive/2008/08/13/1266946.html
After the article "Practical Project Analysis" was published, many of my friends commented and discussed it very enthusiastically. I also replied to some of my friends' messages and communicated with each other to improve them!
1.Avoid the problem of multiple layers of business entities
First of all, in a layered architecture, what we should try to avoid is to trigger the whole body, but in some cases this is inevitable. Any solution can only solve some problems, not all problems, in addition, a new solution may bring new problems.
I listed several solutions that I could think of, and used a typical "add field" example to illustrate their respective advantages and disadvantages:
A.Each layer uses its own model for translation during transmission. For exampleDatacontract,BusinessEntity,DatatableThe Domain Models Corresponding to the presentation layer, business logic layer, and data access layer are translated between layers during transmission. This can be used for separation.WCFIn this regard, it is very good, it forces developers to useDatacontractThe data interface of the system, and its implementation is blocked.
This scheme is the most common, but it cannot solve the problem of adding a field. When a field needs to be added,DT,Be,DCMust be modified. In addition, translation operations may cause some efficiency losses.
B.Each layer uses the same model. For example, all layers use business objects. ExploitationC #OfPartialClass, each layer only defines the data that you care about, and can also achieve isolation effect. I have met a foreigner project with this design.
This solution partially solves the problem of "adding fields. First, we add a field to the database table.PartialAddPropertyAdd a value assignment statement, and add a control at the presentation layer. This avoids modifying the business logic layer (of course, when the business logic layer does not process this field ). This solution can solve the problem of adding fields,PartialClasses are too scattered.CodeReading is difficult.
C.Customize data description. That is, the data itself contains metadata, suchXML. But this will also bring about another problem. This will go to another extreme, that is, the weakening of object-oriented. Any data isXMLWithout the advantages of object-oriented. You can also create anotherXMLTo the object conversion platform, but it will increase a lot of work.
If the platform is set up, the problem of "adding fields" can be solved, becauseXMLIt is self-describing. You can add a lot of metadata to describe the attributes of data at each layer (for example, data structure, whether it is converted to an object, whether it is visible on the interface, etc)
The above are some of the methods I have come up with and met. I hope you can correct them.
2.Interface-Oriented Programming
We are also concerned about this. I will clarify here: I did not say that interfaces are omnipotent, and interfaces are certainly not omnipotent, and it is impossible to solve all problems. What I'm talking about is that interfaces are the basis for eliminating dependencies, and are the main means to eliminate dependencies in the Object-Oriented field at present.
In the current era when object-oriented technology is the main theoretical basis, including design patterns and architecture patterns, one of the core ideas is to eliminate dependencies and encapsulate changes, while interfaces are the main means.
Welcome to continue the discussion! :-)
After the article "Practical Project Analysis" was published, many of my friends commented and discussed it very enthusiastically. I also replied to some of my friends' messages and communicated with each other to improve them!
1.Avoid the problem of multiple layers of business entities
First of all, in a layered architecture, what we should try to avoid is to trigger the whole body, but in some cases this is inevitable. Any solution can only solve some problems, not all problems, in addition, a new solution may bring new problems.
I listed several solutions that I could think of, and used a typical "add field" example to illustrate their respective advantages and disadvantages:
A.Each layer uses its own model for translation during transmission. For exampleDatacontract,BusinessEntity,DatatableThe Domain Models Corresponding to the presentation layer, business logic layer, and data access layer are translated between layers during transmission. This can be used for separation.WCFIn this regard, it is very good, it forces developers to useDatacontractThe data interface of the system, and its implementation is blocked.
This scheme is the most common, but it cannot solve the problem of adding a field. When a field needs to be added,DT,Be,DCMust be modified. In addition, translation operations may cause some efficiency losses.
B.Each layer uses the same model. For example, all layers use business objects. ExploitationC #OfPartialClass, each layer only defines the data that you care about, and can also achieve isolation effect. I have met a foreigner project with this design.
This solution partially solves the problem of "adding fields. First, add a field to the database table.PartialAddPropertyAdd a value assignment statement, and add a control at the presentation layer. This avoids modifying the business logic layer (of course, when the business logic layer does not process this field ). This solution can solve the problem of adding fields,PartialClasses are too scattered, making it difficult to read the code.
C.Customize data description. That is, the data itself contains metadata, suchXML. But this will also bring about another problem. This will go to another extreme, that is, the weakening of object-oriented. Any data isXMLWithout the advantages of object-oriented. You can also create anotherXMLTo the object conversion platform, but it will increase a lot of work.
If the platform is set up, the problem of "adding fields" can be solved, becauseXMLIt is self-describing. You can add a lot of metadata to describe the attributes of data at each layer (for example, data structure, whether it is converted to an object, whether it is visible on the interface, etc)
The above are some of the methods I have come up with and met. I hope you can correct them.
2.Interface-Oriented Programming
We are also concerned about this. I will clarify here: I did not say that interfaces are omnipotent, and interfaces are certainly not omnipotent, and it is impossible to solve all problems. What I'm talking about is that interfaces are the basis for eliminating dependencies, and are the main means to eliminate dependencies in the Object-Oriented field at present.
In the current era when object-oriented technology is the main theoretical basis, including design patterns and architecture patterns, one of the core ideas is to eliminate dependencies and encapsulate changes, while interfaces are the main means.
Welcome to continue the discussion! :-)