Utilization

[Previous] [Next]

Use the Object By Value design pattern in the following circumstances:

  • To pass or return a copy of an object to a caller This will protect the original object from unwanted state changes. For example, you can modify the property values of an object that is passed or returned by value without impacting the original object.
  • To pass or return a copy of an object from one process to another This allows the recipient process to fully benefit from the services offered by an object without having to incur the performance cost usually associated with cross-process object interaction. When a COM object is created in the client process, the client directly references a memory address in its process space, resulting in immediate method invocation. COM objects created outside the client process suffer from significantly slower response times because a client process cannot reference the memory addresses of objects in other processes. Instead COM interposes and creates a proxy object in the client process that the client references directly in memory. When the client invokes a method on the object, a procedure known as marshaling occurs: The proxy object packages the request into a well-defined data packet and forwards the request to a stub object that unpackages the request and invokes the method on the real object. The reverse occurs if the method has a return value or has parameters that are passed by reference. To avoid the major performance hit involved in marshaling data across process boundaries you can create a copy of the object in the client process. All object method invocations will then happen directly on the local copy of the object.
  • To pass or return a copy of an object between dissimilar object systems This task is difficult to accomplish without using the Object By Value design pattern. For example, you might want to create the original object in Visual Basic and then pass a copy of it to a Java application. Java and Visual Basic have different semantics and syntax for defining an object, but, providing both sides agree on how to interpret a data stream, it's possible to "re-hydrate" an object created in one language platform in another.


Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net