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.
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:
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.