Martin's enterprise application architecture model # post-reading # first, this book was written before Year 89, and the translation is quite different from the popular terms, for example, the field is often translated into a "field", and the translation into a "field" in the book has been depressing for a long time. I don't understand what the "field" is... therefore, you need to have one more eye for choosing books in the future. However, the book is still very good. Although it is a bit obscure, it is quite fun to read it.
ResponsivenessUnlike request processing, it is how fast the system responds to requests. This indicator is very important in many systems, because for some systems, if their response is too slow, users will be unbearable-although their response time may not be slow. If some information can be sent to the user before the processing is completed, it indicates that the system has received the request, the response will be better. For example, progress bar.
A general principle on dependency: The domain layer and Data Source layer must not depend on the presentation layer.
The organization of domain logic can be divided into three main modes:
Transaction script ,
Domain Model And
Table Module .
Transaction scriptYesProcess: Obtain input from the presentation layer, perform verification and calculation, store data in the database, and call other system operations.The basic organizational structure is to make each process correspond to a user's possible action.Therefore, we can think of this model as a script for action or business transactions. Each action is driven by a process.
In a domain model, it is no longer a process to control the logic of a user's action, but a part of the relevant logic is assumed by each object.
In many ways,
Table Module It is an intermediate area of the transaction script and domain model. It organizes domain logic around the table rather than directly surrounding the process, provides more structures, and is easier to detect and remove redundancy. Code . However, you cannot apply many techniques that can be used in Domain Models to organize fine-grained logical structures, such as inheritance, policies, and other object-oriented design patterns.
Generally,
Serialization Lob (large object) for Application Composition Program Some are the best for independent object groups. However, if you use it too much, the database will eventually be similar to the transaction file system.
There are generally three options for any inheritance structure. You can create a table for all classes in a hierarchy, that is
Single Table inheritance You can also create a table for each specific class, that is
Specific table inheritance Or create a table for each class in this level:
Class table inheritance .
These three methods have advantages and disadvantages. Single-Table inheritance wastes space, but avoids join operations. A specific table inheritance has to change all tables when the superclass changes, but it also avoids join operations and allows an object to be obtained from a table; class table inheritance requires multiple join operations to load an object, which usually results in a loss of performance, but it is the simplest relationship between classes and tables.
If the machine is under the control of the screen stream, you needApplication ControllerIf the machine is under user control, you should not apply the controller.
Three modes can be considered for the View:Conversion View,Template ViewAndTwo-step View.
In essence, it is not enough to consider the correctness of any concurrent program. Flexibility must also be considered (that is, how many concurrent activities can be performed simultaneously ). People often need to sacrifice some correctness to get more flexibility, depending on the severity and likelihood of failure and people's needs for Concurrent Data Processing.
There are two very important solutions to the concurrency problem: one is isolation and the other is immutability ).
The criteria for selection between optimistic locks and pessimistic locks are the frequency and severity of conflicts. If there are few conflicts, or the consequences of the conflicts are not very serious, you should choose optimistic locks in general, because it can get better concurrency and be easier to implement. However, if the conflicting results are painful for the user, the pessimistic lock policy should be used.
Timeout control and detection mechanisms are used to handle deadlocks. Other methods are used to prevent deadlocks.
Transactions that span multiple requests are calledLong transaction.
Start the transaction at the beginning of the request and commit the transaction at the end of the request. This isRequest transaction.
Another way is to open the transaction as late as possible. UseDelay transactionsThe Data Reading operation should be completed outside the transaction, and the transaction should be started only when the data is modified. However, this may causeInconsistent readProblem.
The transaction isSerializable(Serializable ).
If there are many users in the system, you should consider using clusters to increase the throughput.Session migration(Session migration) allows one session to be transferred from one server to another, so that one server can process one request and other servers can process other requests. The opposite method is:Server affinityServer affinity, which requires that all requests for a specific session can only be processed by the same server.
First Law of Distributed Object Design: Do not distribute objects.
In this case, how can we effectively use multi-processor resources? In most cases, the cluster system is used. Deploy all objects on each processor and copy them on several other nodes. In this way, the objects on each processor only need to be called locally to run faster. You can also use fine-grained interfaces to design objects to obtain a simpler programming model and better maintainability.
Transaction script(Transaction script): processes are used to organize business logic. Each process processes a single request from the presentation layer.
Never letTransaction scriptCall any presentation layer logic; this will make it easy for us to modify code and TestTransaction script.
Domain ModelDomain Model: an object model that combines behavior and data fields.
As the logic layer of enterprise-level applications,Service LayerCombining scripts and domain objects, we found a balance between the strengths of the two. There are some optional solutions for implementationService LayerSuch as the domain appearance or operation script, pojo, or session beans, or a combination of the two. Most importantly, no matter which implementation method is used,Service LayerThis model lays the foundation for encapsulating application business logic, implementing and supporting different customers to call these logics in the same way.
Activity records: An object that encapsulates a row in a database table or view, encapsulates database access, and adds domain logic to the data.
Activity recordsAndRow Data EntryVery similar. The main difference between the two is:Row Data EntryOnly Database AccessActivity recordsThere are both data source logic and domain logic.
Offline concurrency(Offline concurrency), which means to control the concurrency of Data Operations in multi-database transactions.
If each transaction processes the tables to be edited in the same order, the risk of deadlock is greatly reduced.Work UnitIt is an ideal place to store the sequence of fixed write tables, so that tables can be accessed in the same order.
Work UnitThe basic problem solved is to record various objects that have been operated, so that you can know which objects need to be taken into account in order to synchronize data in the memory with the database.
Work UnitIs to save all the information in one place. Once usedWork Unit. And,Work UnitIt can also be used as a fixed processing platform in more complex situations, such as processing a ExploitationOptimistic offline lockAndPessimistic offline lockBusiness transactions that span several system transactions.
GenerallyId ingTo manage read objects of all modified databases.Id ingAnother purpose is to serve as the high-speed cache for database read operations.
There are four main implementationsDelayed LoadingMethod:Delayed initialization, virtual proxy, value holder, and shadow.
Delayed LoadingIt is suitable for Aspect-Oriented Programming.
This is often the case where different use cases and differentDelayed loading policyBest combination.
Method object(Method object): it converts a complex method into an object independently. Its biggest advantage is that it allows entering values in the field rather than passing values through parameters.
MVCThe value mainly lies in two separation. The separation of views and models is one of the most important software design principles. The separation of views and controllers is slightly less important.
ForRemote appearanceOne of the biggest mistakes is to put the domain logic in it. Any appearance should be a thin layer of skin and be only responsible for a small part of the responsibility.
InData transmission objectFields in are very simple and primitive, such as simple classes such as strings and dates. AnyData transmission objectThe structure between them should be very simple-it is a layered structure, unlikeDomain ModelThe complex structure shown in. InData transmission objectSo many simple attributes are stored to serialize them, and it is easier for both parties to understand the transmission.
The last thing to handle is the lock timeout in the lost sessions. If the client crashes in the middle of the transaction, the lost transaction cannot be completed, and the lock occupied by the client cannot be released. Ideally, let the app ServerTimeout MechanismRather than the application itself. The Web Application Server provides HTTP session management. Timeout: You can register a listener to release the lock occupied by the listener when the http session is invalid.
Another method is to add a timestamp to each lock to regularly clear the locks that have exceeded a certain period of time.
Locking each entity in the system will inevitably lead to frequent data competition.RememberPessimistic offline lockJustOptimistic offline lockSupplement, Used only when neededPessimistic offline lock.
System transactions: Occurs between applications and databases.
Business transactions: Occurs between the user and the application.
UseOptimistic offline lockShare each object in the group with the same version number to create a control point. This means that they share the same version number instead of having the same version number. When this version number is added, it becomes a lock group for all objectsShared lock(Shared lock ).
Customer session StatusIf HTML is used, there are generally three methods: URL parameters, hidden fields of forms, and cookies.
In the selectDatabase session StatusAndServer session StatusThe key depends on the use of specific application servers.Server session StatusEase of cluster and fault recovery. GenerallyDatabase session StatusCluster and fault recovery should be more direct.
If you must use a complex interface to interact with things outside the system, considerPortalGateway ). UsePortalEncapsulate the complexity, rather than spreading the complexity to the entire system. UsePortalThere are almost no drawbacks, and code readability beyond the entry class in the system can be significantly improved.
The book has been read and will not be updated.