Activity record of data source architecture Mode

Source: Internet
Author: User
Tags php example

[Intention of activity record]

An object that encapsulates a row in a data table or view, encapsulates database access, and adds domain logic to the data.

[Applicable scenarios of activity records]

Applicable to less complex domain logic, such as CRUD operations.

[Operation Mechanism of activity records]

Objects have both data and behavior. It uses the most direct method to place the data access logic in the domain object.

Activity records are essentially a domain model. The classes in this domain model should be exactly matched with the record structures in the database. each field of the class corresponds to each column of the table.

Generally, activity records include the following methods:

1. Construct an activity record instance from a data row;

2. construct a new instance for future table inserts;

3. Use static search methods to encapsulate common SQL queries and return activity records;

4. update the database and insert the data in the activity record into the database;

5. Obtain or set the domain;

6. implement some business logic.

[Advantages and disadvantages of activity records]

Advantages:

1. simple, easy to create, and easy to understand.

2. Reduce code replication when using transaction scripts.

3. Domain logic is not changed when the database structure is changed.

4. derivation and test verification based on a single activity record are very effective.

Disadvantages:

1. No hidden relational database exists.

2. The activity record is valid only when the activity record object is directly matched with the table in the database.

3. requires tight coupling between object design and database design, which makes it difficult to further reconstruct the project.

Activity record and other modes]

Data source architecture mode: the row data entry is similar to the row data entry. The main difference between the two is that the row data entry only has database access, and the activity records have both data source logic and domain logic.

PHP example of activity record]

 

 
 
  1. <? Php
  2. /**
  3. * Activity record of enterprise application architecture data source architecture mode 2010-10-17 sz
  4. * @ Author phppan. p # gmail.com http://www.phppan.com
  5. * Members (http://www.blog-brother.com /)
  6. * @ Package architecture
  7. */
  8. /**
  9. * Order Type
  10. */
  11. Class Order {
  12. /**
  13. * Order ID
  14. * @ Var <type>
  15. */
  16. Private $ _ order_id;
  17. /**
  18. * Customer ID
  19. * @ Var <type>
  20. */
  21. Private $ _ customer_id;
  22. /**
  23. * Order amount
  24. * @ Var <type>
  25. */
  26. Private $ _ amount;
  27. Public function _ construct ($ order_id, $ customer_id, $ amount ){
  28. $ This-> _ order_id = $ order_id;
  29. $ This-> _ customer_id = $ customer_id;
  30. $ This-> _ amount = $ amount;
  31. }
  32. /**
  33. * Instance deletion
  34. */
  35. Public function delete (){
  36. $ SQL = "DELETE FROM Order SET WHERE order_id =". $ this-> _ order_id. "AND customer_id =". $ this-> _ customer_id;
  37. Return DB: query ($ SQL );
  38. }
  39. /**
  40. * Instance update operations
  41. */
  42. Public function update (){
  43. }
  44. /**
  45. * Insert operation
  46. */
  47. Public

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.