When the caller uses the "management class" method, write a call similar to the following: Code :
Idbmembernamecardmanager ncmgr = Memberfacade. getinstance (). createdbmembernamecardmanager ();
Imembernamecard NC = Ncmgr. readmembernamecard (currentmember. ID );
// Display the company name in the business card in the label
This . Labelcompany. Text = NC. Company;
In this way, the caller needs to know
1. The domain information interface is the aforementioned interface imembernamecard and currentmember (current user), that is, the domain class ".
2. Method interface for accessing domain information, that is, the aforementioned idbmembernamecardmanager, also known as "Management (manager) Class ".
3. Obtain the facade of the management class, that is, the above memberfacade, that is, the class factory.
Now we use another mode:
Imembernamecardadapter Adapter = (Imembernamecardadapter) currentmember. getadapter ( Typeof (Imembernamecardadapter ));
If (Adatper ! = Null )
{
Imembernamecard NC = Adapter. readmembernamecard ();
This . Labelcompany. Text = NC. Company;
}
In this way, the caller only needs to know domain information and access interfaces. Does it look more concise?
This mode is widely used in eclipse. You can add many different adapters to the domain class without requiring the domain class to directly implement new interfaces, thus avoiding "interface swelling ".
The less customers know the better, I think this is the essence of this model.
Note: The support for this mode requires some environment support. I have also uploaded a C # project about the adapter mode to simulate this support.