
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Controlling Access to Types in a Local Assembly
|
947
Note that as long as the CompanyData object was accessible, you could have also writ-
ten this to access the object directly:
// Instantiate the CompanyData object directly without a proxy.
CompanyData companyData = new CompanyData( );
// Read some data.
Console.WriteLine("CEOPhoneNumExt: " + companyData.CEOPhoneNumExt);
// Write some data.
companyData.AdminPwd = "asdf";
companyData.AdminUserName = "asdf";
// Save and refresh this data.
companyData.SaveNewData( );
companyData.RefreshData( );
If these two blocks of code are run, the same fundamental actions occur: data is read,
data is written, and data is updated/refreshed. This shows you that your proxy
objects are set up correctly and function as they should.
Discussion
The proxy design pattern is useful for several tasks. The most notable—in COM,
COM+, and .NET remoting—is for marshaling data across boundaries such as
AppDomains or even across a network. To the client, a proxy looks and acts exactly the
same as its underlying object; fundamentally, the proxy object is just a wrapper
around the object.
A proxy can test the security and/or identity permissions of the caller before the
underlying object is created or accessed. Proxy objects can also be chained together
to form several layers ...