tailieunhanh - Practical Apache Struts2 Web 2.0 Projects retail phần 10

Sở thích của tôi là DTO, như tên gọi tốt hơn mô tả các chức năng của đối tượng trong con thoi dữ liệu từ một lớp khác. Trong trường hợp của EventDTO, đối tượng là không thay đổi. Điều này làm cho cảm giác khi chuyển dữ liệu đến một giao diện người dùng, nhưng nó không phải là luôn luôn như vậy. | 304 CHAPTER 10 AJAX DATA TRANSFER OBJECTS Data Transfer Objects DTOs as the name suggests are objects that transfer data and were first introduced by Martin Fowler in Patterns of Enterprise Application Architecture. Another term Value Object is also used to describe objects that perform the same job. My preference is for DTO as the name better describes the function of the object in shuttling the data from one layer to another. In the case of the EventDTO the object is immutable. This makes sense when transferring data to a user interface but it isn t always the case. Here are some of the other characteristics that a DTO can exhibit They provide a representation of another object or they can provide a representation of data elements from multiple objects which are usually related . dependent object . They can be mutable or immutable. They may or may not provide all the properties from the object they represent. The properties from the represented object may be simplified . providing a string representation of a date object . There may be multiple DTO representations for a single domain object with each new representation provided for a specialized task. Multiple objects providing specialized representations is preferred over a sparsely populated DTO because when sparsely populated the DTO consumer may be uncertain as to whether the property exists and is not available or whether the value is null. DTOs are useful but like any tool can be overused. When introducing DTOs make sure there is a specific purpose that they are being used for. Too often DTOs can complicate an application s architecture by adding unneeded layers of abstraction. The transformation from Location to LocationDTO occurs in the constructor of the Event-DTO class and the transformation from Event to EventDTO is performed in the getDtoResults method on the ShowRecentEventsAction class. This is a new method introduced for the purpose of returning a list of DTO objects. Having it available on .

TỪ KHÓA LIÊN QUAN