sẽ có nghĩa là một sự thay đổi tương tự như ở nhiều nơi khác. Nếu bạn đã hardcoded các cuộc gọi đến một lớp học Mailer, hoặc một lớp học để soạn văn bản, sau đó hệ thống của bạnbất động sản). Nó cũng bao gồm những từ khoá đặc biệt được gọi là thẻ. | CHAPTER 13 DATABASE PATTERNS As you can see this class extends a standard Eventcollection. Its constructor requires EventMapper and PDOStatement objects and an array of terms that should match the prepared statement. In the first instance the class does nothing but store its properties and wait. No query has been made of the database. You may remember that the Collection base class defines the empty method called notifyAccess that I mentioned in the Data Mapper section. This is called from any method whose invocation is the result of a call from the outside world. DeferredEventCollection overrides this method. Now if someone attempts to access the Collection the class knows it is time to end the pretense and acquire some real data. It does this by calling the PDOStatement execute method. Together with PDOStatement fetch this yields an array of fields suitable for passing along to Mapper createObject . Here is the method in EventMapper that instantiates a DeferredEventCollection EventMapper namespace woo mapper . function findBySpaceId s_id return new DeferredEventCollection this this- selectBySpaceStmt array s_id Consequences Lazy loading is a good habit to get into whether or not you explicitly add deferred loading logic to your domain classes. Over and above type safety the particular benefit of using a collection rather than an array for your properties is the opportunity this gives you to retrofit lazy loading should you need it. Domain Object Factory The Data Mapper pattern is neat but it does have some drawbacks. In particular a Mapper class takes a lot on board. It composes SQL statements it converts arrays to objects and of course converts objects back to arrays ready to add data to the database. This versatility makes a Mapper class convenient and powerful. It can reduce flexibility to some extent however. This is especially true when a mapper must handle many different kinds of query or where other classes need to share a Mapper s functionality. For the .