PEAA notes 6: Active Record

xiaoxiao2021-03-06  41

What is IT Active Record wrapped in a line of data in a data sheet or view, encapsulated its database access behavior and joined the data of the data. It can also be seen, Active Record is Domain Object ^ _ ^ joined database access behavior

How IT Works Active Record can include all business logic of data records, or only ordinary data-oriented logic, which uses the remaining business logic to implement Active Record through Transaction Script, which often implements the following methods: 1. Construct an Active Record instance 2 by SQL query results. For the insertion database operation, you will be a Active Record instance 3. Static Finder method returns Active Record object 4. By Active Record object Update database and INSERT database 5. Get / set data domain 6. Realize some business logic due to the close coupling of Active Record and databases, we often see static Finder methods in this mode, of course, can also put these Finder methods in a class.

One advantage of WHEN to Use IT Active Record is relatively simple, and works well in Domain Model in Domain Model in a single data record, is Active Record and Data Mapping, the former is relatively simple, and more suitable for solving The object model is just a service area of ​​the table structure in the database. But the problem is that if the obligatory logic is more complicated, you want your object model to handle relationships, collections, inheritance, etc., Active Record does not look at it, this is another problem with Active Record when using Data Mapper. The design of the object model is closely coupled together, and the modification and reconstruction is difficult. If you use Transaction Script, then Active Object is also a good pattern, which helps you reduce the code repeat.

转载请注明原文地址:https://www.9cbs.com/read-77325.html

New Post(0)