Chapter 5 -- Bridge

[Previous] [Next]

Chapter 5

As defined in Chapter 2, interface inheritance is the means by which you obtain reusability in Microsoft Visual Basic. Different classes can inherit the same interface. Each class can then define a unique implementation for that interface. An object exposes the interfaces supported by the class the object is based on. Communication with an object is possible only through the interfaces it exposes.

For this reason, a Visual Basic object-oriented developer programs to an interface rather than to a class. As a result, an ideal system is said to exist when the consumer code, which initiates interaction with one or more interfaces, is written only once. The objects that are bound to the interfaces used by the consumer can easily be replaced by other objects of different classes, so long as those classes support the same interfaces. Binding to a different object results in different behavior of the consumer for the same interfaces, which leads to polymorphism. As you'll recall from Chapter 2, polymorphism is the ability to dynamically bind an interface to an object that supports it.

As you'll also recall from Chapter 2, reusing an interface requires you to use the keyword Implements, followed by the interface name, in a given class module. The class must then implement all the properties and methods defined in that interface. This is the conventional way to reuse an interface, but the Bridge design pattern accomplishes the same end while providing benefits not realized with interface inheritance.



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