Chapter 2 -- Understanding Interface-Based Programming

[Previous] [Next]

Chapter 2

Getting a grasp of interface-based programming is really tough. To gain an appreciation for this style of programming, you must leave behind old habits and intuitions about writing code and look back at the evolution of object-oriented programming (OOP) and computer science over the past decade—a Darwinian saga of how the interface has made modern software designs more fit for survival. For software to survive in the ever-changing jungle of the production environment, it must have three distinct characteristics: reusability, maintainability, and extensibility. This chapter provides a general overview of interface-based programming and examines these characteristics.

COM is founded on the idea of interface-based programming, a style of programming in which the interface is separate from implementation. (COM has no meaning without the concept of the interface. Interfaces, on the other hand, exist outside the world of COM.) Interface-based programming was pioneered in languages such as C++ and Smalltalk by software engineers who discovered that using distinct interfaces could make their software, especially large applications, easier to maintain and extend. (The creators of Java saw the elegance of interface-based programming and consequently built support for it directly into their language.)

Interfaces solve many problems associated with code reuse in OOP. This chapter investigates some of these problems. In particular, when you program in a style consistent with classic OOP, a client can build inflexible dependencies on a class definition. These dependencies can make it difficult to maintain or extend the class without breaking the client. It becomes tedious or impossible to improve the code for an object over time. Certain problems are also associated with a popular OOP language feature known as implementation inheritance. This powerful but often misused feature is vulnerable to similar dependency problems, which compromise an application's maintainability and extensibility. This chapter describes the strengths and limitations of implementation inheritance (even though this type of inheritance is not supported by Visual Basic) in order to address some of the problems that interface-based programming was created to solve.

Visual Basic 5.0 was the first version of the product to include support for defining and implementing user-defined interfaces. This chapter shows you how to program in terms of interfaces in a Visual Basic application. After covering the basics of using interfaces, I'll demonstrate how to achieve polymorphism and how to use runtime type inspection.

As you'll see in the next chapter, COM clients must communicate with objects through interfaces. You should always keep in mind, however, that Visual Basic doesn't require you to program explicitly in terms of user-defined interfaces. At times, you actually can't create components that implement user-defined interfaces. You have to work in terms of classes with public methods. This is typically the case when you're creating servers for scripting clients.

Programming with user-defined interfaces provides benefits at the cost of additional complexity. The goal of this chapter is to prove to you that the benefits can be greater than the costs.



Programming Distributed Applications with COM+ and Microsoft Visual Basic 6.0
Programming Distributed Applications with Com and Microsoft Visual Basic 6.0 (Programming/Visual Basic)
ISBN: 1572319615
EAN: 2147483647
Year: 2000
Pages: 70
Authors: Ted Pattison

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