tailieunhanh - Expert VB 2005 Business Objects Second Edition phần 2

Các phương pháp tiếp cận phụ trách lớp học là một biến thể trên các mẫu thiết kế Nhà máy, trong đó một phương pháp "nhà máy" là chịu trách nhiệm cho việc tạo và quản lý một đối tượng. Trong nhiều trường hợp, các phương pháp này nhà máy được chia sẻ các phương pháp có thể được đặt trực tiếp | 46 CHAPTER 2 FRAMEWORK DESIGN Note The class-in-charge approach is a variation on the Factory design pattern in which a factory method is responsible for creating and managing an object. In many cases these factory methods are Shared methods that may be placed directly into a business class hence the class-in-charge In this model I ll make use of the concept of Shared factory methods on a class. A Shared method can be called directly without requiring an instance of the class to be created first. For instance suppose that a Customer class contains the following code Serializable _ Public Class Customer Public Shared Function NewCustomer As Customer Dim svr As AppServer _ CType GetType AppServer _ http myserver myroot AppServer Return End Function End Class Then the UI code could use this method without first creating a Customer object as follows Dim cust As Customer A common example of this tactic within the .NET Framework itself is the Guid class whereby a Shared method is used to create new Guid values as follows Dim myGuid As Guid This accomplishes the goal of making the UI code reasonably simple but what about the Shared method and passing objects by value Well the NewCustomer method contacts the application server and asks it to create a new Customer object with default values. The object is created on the server and then returned back to the NewCustomer code which is running on the client. Now that the object has been passed back to the client by value the method simply returns it to the UI for use. Likewise you can create a Shared method in the class in order to load an object with data from the data store as shown Public Shared Function GetCustomer ByVal criteria As String As Customer Dim svr As AppServer _ CType GetType AppServer _ http myserver myroot AppServer Return criteria End Function Again the code .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.