dcsimg
December 8, 2016
Hot Topics:

VB6 Programmer's Introduction to COM

  • November 19, 2002
  • By James Limm
  • Send Email »
  • More Articles »

If we follow the COM model we will create components described in such a way that they can interact with one another at runtime. The COM model specifies what the interfaces of a component must look like at the binary level, which means that provided your programming language can produce code that obeys the specification, it doesn't actually matter which one you use. This is how COM's much-vaunted language independence is achieved.

Defining COM in a few words is not the easiest thing to do because it comprises several things. Let's expand on the explanations I've given so far by examining exactly what it is that COM provides.

COM is a framework for creating and using components

Because COM is a language-independent standard, it's possible to build and subsequently use components with different languages such as Visual Basic, Visual C++, Delphi or Visual J++. A COM client (sometimes also called a container) is an application whose architecture supports the use of these software components.

COM provides a mechanism for components to communicate with each other

COM achieves the communication promised by the title of this section by the combination of two things. First, there is the binary standard it imposes, which means that your components not only provide a mechanism to communicate, but also know how to speak to other COM-enabled components or applications.

Second, there is the set of services provided by the COM runtime (also called the COM library) that is required to be present on a computer before communication between the components can occur. These services, which are available to all components, come in the form of a set of API functions.

COM promotes the use of component-based development

Before the advent of component-based development, the predominant technique was procedure-based development. This style is linear in nature, and programs written using it start at the first line of code, and finish either when the last line is executed, or an Exit statement is reached. Applications written in this fashion tended not to be very adaptive to what was happening around them.

In Visual Basic today, it is quite easy to reference (that is, to plug in) a library of functionality. Where we used to have to write complex API calls to talk to a database, we now simply have to set a reference to the appropriate library of functionality (as in the following figure) to be able to use it in our own programs. In this particular instance, we're creating a reference in our Visual Basic project to a COM-based library that will allow us to communicate with a database:

Component-based development also allows the programmer to take advantage of using pre-packaged components or tools. An example would be if you were writing a communications program that dealt with receiving and sending information over a modem. You could go out and buy (fairly inexpensively) a package that would handle the communications functionality for you, ridding yourself of the need to write large amounts of code to see if a port was open. You would just have to reference the library, and write a small amount of your own code. These libraries may be thought of as black boxes: you don't need to concern yourself with how they work; you just know that they do work.

COM promotes object-oriented programming

COM (and component-oriented design in general) was created with object-oriented programming in mind. This is a methodology that promotes thinking about software 'objects' and the way those objects interact with each other, rather than their implementation. Although this isn't a book on OOP, it is very difficult to discuss COM programming without covering many aspects of object-oriented programming. Therefore, from time to time we will be discussing further some of the aspects of object-oriented programming.





Page 4 of 12



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel