Sample Application

[Previous] [Next]

I have created a home security system, located on the companion CD, to illustrate the benefits of local/remote transparency coupled with optimal performance. The home security system allows the user to activate or deactivate particular features either from within the home through a direct link on a desktop computer or remotely with a laptop computer through a dial-up line. The remote access enables home owners to rest assured that their property is secure even when they are out of town. A great selling point of my system is that—unlike the competition—interfacing with the system through a dial-up line instead of the direct link has almost no noticeable performance difference. Hence, home owners have confidence in the system whether they are at home or away.

OK, my home security system doesn't really work, but it is a fully functioning simulation. Of course, the main focus here is how I used the Smart Proxy design pattern in my system architecture. Access to the system is transparent to the user whether or not she is at home, because the graphical user interface is the same, the process of connecting is the same, and the performance cost from dialing up is so small as to be unnoticeable. Implementing the Smart Proxy design pattern affords the same benefit from a software development standpoint, which is local/remote transparency without changing the interface to the real object or compromising performance. Table 7-1 lists the components that form the home security system.

Table 7-1. Components of the Home Security System

Components Contents
SecurityLib.tlb (Type Library) Interfaces SecurityGuard and DataStream are compiled here.
RealGuardLib.dll (ActiveX DLL) RealGuard class is defined here.
SecurityProducerLib.dll (ActiveX DLL) Classes SecurityGuardFactory and SmartGuard are defined here.
RemSecureAdvisor.exe (ActiveX EXE) Remote RealGuard instances reside here.
HomeSecure (Standard EXE) Client of an object that supports the SecurityGuard interface.

The home security system exhibits the applicability of the Smart Proxy design pattern; however, it might require the conglomeration of various design patterns to develop the architecture necessary for the system to function correctly. Figure 7-4 paints a clear picture of the home security system process using COM object notation. Following is a brief synopsis that emphasizes the use of the Smart Proxy design pattern, but that includes other dependent pieces that assist in defining the required behavior of the Smart Proxy design pattern. Refer to the sample code on the companion CD for the full disclosure.

  • SecurityGuard interface (Abstraction) This is the interface expected by the client (HomeSecure). The client expects some behavior manifested by an object that supports this interface, more so when the client makes requests.
  • DataStream interface This interface was designed with the intent to serve as a conduit for sending and receiving streams of instructions between the smart proxy (SmartGuard) and the real object (RealGuard). The client need not be aware of or concerned about the existence of this interface. This is purely an implementation detail agreed upon by SmartGuard and RealGuard.
  • RealGuard (RealClass) This class implements the behavior for the SecurityGuard interface. To simulate the activation and deactivation of security features (such as engaging the electric fence or releasing the alligators into the pit), RealGuard persists its state in a security.ini file. The next time the user loads the client (HomeSecure), an instance of RealGuard will load its state from the INI file. RealGuard also implements the DataStream interface, for which it defines the behavior for sending and receiving a batch of instructions in one invocation.
  • SmartGuard (SmartProxy) This class represents the real object (RealGuard) in the client (HomeSecure) process's address space when the real object is in a remote location (RemAdvisor). For optimal performance, the state of RealGuard is cached in SmartGuard, and requests to update the state or invoke behavior in RealGuard can be packaged as a compound instruction. The requests are then sent in a single invocation to the RealGuard object via DataStream interface operations.
  • SecurityGuardFactory This class provides local/remote transparency to the client (HomeSecure) by creating an instance of an object that supports the SecurityGuard interface. If the home owner is at home, SecurityGuardFactory will create an instance of RealGuard in the HomeSecure process's address space. If the home owner is away, SecurityGuardFactory creates an instance of SmartGuard in the HomeSecure process's address space that references a RealGuard object, which resides in the address space of a remote process (RemAdvisor). As the following code extract illustrates, the CreateInstance method of SecurityGuardFactory accepts an enumerated data type, Location, as a parameter to simulate the choice of the home owner using the home security system from a direct link at home (AT_HOME), or on a dial-up line away from home (ON_THE_ROAD).
  •  ' Project: SecurityProducerLib ' File Name: SecurityGuardFactory.cls ' Copyright: 1/99 Bill Stamatakis ' Class Name: SecurityGuardFactory  Public Function CreateInstance(WhereAmI As Location) As _ SecurityLib.SecurityGuard Select Case WhereAmI Case AT_HOME Set CreateInstance = New RealGuardLib.RealGuard Case ON_THE_ROAD Set CreateInstance = New SmartGuard End Select End Function 

  • HomeSecure (Client) This application is a client that expects an object that supports the SecurityGuard interface through which the core functionality of the home security system is defined.
  • RemAdvisor (Remote Process) This ActiveX EXE serves as a residence for the RealGuard object from which a COM proxy is generated and returned to the HomeSecure client. A SmartGuard object encapsulates the reference to this proxy through which all requests intended for the RealGuard are ultimately submitted.

click to view at full size.

Figure 7-4. Home Security system architecture diagram.



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