9.6. Marshal by Value (MBV)
Example 9-11 contains yet another version of ServerInfo. There are only two differences between this version and the last:
The class is marked <Serializable> instead of derived from MarshalByRefObj, which is required to marshal an object by value.
All data that is provided by the class is obtained in the constructor instead of at call time.
When ServerInfoFactory.CreateServerInfo is called, all remote machine properties are ascertained immediately. This is necessary because next, the entire class is marshaled by value back to the client; that is, a complete copy is transferred to the client. If the machine values were not obtained in the constructor, the class would return values relative to the client machine (because the object will be local to the client).
|
Example 9-11. MBV version of ServerInfo
<Serializable( )> _ Public Class ServerInfo Implements IServerInfo Private machineTime As DateTime Private processorUsed As Single Private availableMemory As Long Private machine As String Private ip As IPAddress Public Sub New( ) 'Get machine info when object ... |
Get Object-Oriented Programming with Visual Basic .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.