Using Interfaces in Your Application Designs

This chapter has presented a simple application to demonstrate the core concepts of interface-based programming. How can you apply these principles in a real-world application? If you're designing a large application that uses customer objects, you can create a user-defined interface ICustomer and start writing lots of client code against the interface instead of to a concrete CCustomer class. If you create several classes that implement the ICustomer interface, you can achieve the plug-and-play benefits of polymorphism. Different types of customer objects exhibit different behavior, but they're all controlled through the same interface.

From a versioning standpoint, this design lets you improve the behavior of various customer objects by introducing new interfaces into the application. Interfaces such as ICustomer2, ICustomer3, and ICustomer4 let you safely extend the behavior of customer objects. The best part about this approach is that you can revise clients and objects independently. Older clients and objects can use earlier interfaces, while newer clients and objects can communicate through newer interfaces. All of this is made possible through the run-time type inspection of interface support.

Interfaces and COM

The industry has adopted interface-based programming because of the limitations of other common techniques, such as the use of class-based references and implementation inheritance. User-defined interfaces bring a new level of complexity to both application design and programming, but their value is easy to measure in large applications. In a Darwinian sense, interface-based programming makes software more fit for survival. Interfaces make your code easier to reuse, maintain, and extend.

The next chapter presents the internals of COM. As you'll see, COM is based on the following core concepts of interface-based programming:

  • COM requires a formal separation of interface and implementation—that is, it requires that clients communicate with objects exclusively through interface references. This ensures that clients never build dependencies on the classes that serve up objects, which in turn allows COM programmers to revise their object code without worrying about breaking client code.

  • COM clients can get run-time type information from objects. A COM client can always query an object and ask whether it supports a specific interface. If the requested interface isn't supported, the client can discover this and degrade gracefully. This lets programmers revise components and applications independently. Older clients and older objects can work in harmony with newer clients and newer objects. Herein lies the key to versioning in COM.

This chapter showed the use of interfaces in a single application. The entire application was written in a single language, and all the source code was sent to a compiler at the same time. COM, on the other hand, must work across binary components. Moreover, COM clients and COM objects can be written in different languages and can run in different processes on different computers. COM must solve many problems at the physical level to achieve the benefits of interface-based programming.



Programming Distributed Applications With Com & Microsoft Visual Basic 6.0
Programming Distributed Applications with Com and Microsoft Visual Basic 6.0 (Programming/Visual Basic)
ISBN: 1572319615
EAN: 2147483647
Year: 1998
Pages: 72
Authors: Ted Pattison

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