Nancy Cluts
Developer Technology Engineer
Microsoft Corporation
March 17, 1998
Updated: October 12, 1998
The following article was originally published in Site Builder Magazine (now known as MSDN Online Voices).
What do rabbits and object models have in common?
Answer: They seem to multiply like crazy.
One of the most overused and overly complicated programming terms is "object model." For those lacking a degree in computer science, the term is daunting at best. Even more confusing is the fact that the term is used everywhere. This article is for those of you whose eyes glaze over when you hear "object model." By the time you finish this article, you will understand what an object model is and what some of the specific objects models are and where they are used.
In computer-ese, an object is any entity (though I prefer the very technical term "thingy") that you can use or see on the screen.
The object model is the set of rules devised in order to make that object (thingy) do something in particular.
Let's put it in everyday terms: if the object is a car, the object model is the specification for the car that is used for routine maintainence and repairs. The air pressure would be a property and the air inflator would be akin to a method. Using the same car analogy, an event might be the car starting.
In the world of such technologies as Dynamic HTML (DHTML), an example of an object is a window. A method that you can use on a window object is the open method (to open the window). A method is said to be exposed when it is available for use by outside components and applications. An example of a property of an object is the dialogTop property (to get the position of the top of the dialog window). An example of an event is the onClick event. An event is said to be fired when it occurs, so when the user clicks the mouse, the OnClick event is fired. Now, don't you feel savvy already?
The object model that made us all scared of the term object model in the first place is the beloved (and equally despised) Component Object Model (COM). Why is COM beloved? Because COM makes it easier to create components (pieces of code) or use pre-existing components that can interact with other components and applications (using the object model). Another plus is that these components can be written using a variety of computer languages. COM has been around for quite a while, so many programmers have learned how to use it. It's only recently that tools have been made available to simplify the creation of COM objects.
So, why is COM equally despised? When it was introduced, you had to be very, very clever to understand how it worked and how to use it. You had to do absolutely everything yourself, using a new programming concept that few understood, so you were working without a net. Now, you can easily create COM objects (ActiveX controls) using Microsoft Visual Basic® Control Creation Edition or, if you use the C++ language, the Active Template Library (ATL) provided in the Microsoft Visual C++ programming system.
Using Visual Basic, you can create an ActiveX control without having to know about COM by simply choosing to create a new project and specifying "ActiveX Control." Follow the step-by-step instructions in the documentation under "Creating an ActiveX Control" to learn how to create the control, how to use that control from other applications, and how to set properties.
Using the ATL in Visual C++, you can delve into the documentation and take advantage of the "Introduction to COM and ATL"; then the "ATL Tutorial" can walk you through creating an ActiveX control, adding properties, and putting the control on a Web page. After doing that, you can test the control via the ActiveX Control Test Container (which comes with Visual C++).
Now that you know what COM is, let's move on to some technologies that are extensions to COM. It is important to understand that these extensions all are based on COM and use the same object model. They just do different things.
Distributed COM (DCOM) is simply COM over a network. You can use DCOM over a variety of intranets using multiple network transports. A network transport is the language a network speaks, such as the HTTP (HyperText Transfer Protocol) used by Web browsers.
So, why is DCOM cool? Because you can create a component (piece of code) that can run on any machine on your network and interact with other components on any other machine on your network (so long as the components understand DCOM). You simply expose the properties you want to make available to other components or applications you are using. Let's say that you have a ComponentA, which saves information such as the geographical area in which the user resides or works. If you want another component, ComponentB, to use this information, you need to expose the geographical area as a property (.Geography) of ComponentA; ComponentB will need to know the name (.Geography) and syntax (a numerical representation of the city, state, and country, for instance) of the property. Once the properties are exposed, you can take specific actions based on the events that the objects you create support.
COM+, the newest extension to COM, was introduced at the 1997 Microsoft Professional Developers Conference in San Diego to make it easier for developers to use COM. It is language neutral (which means you can use any programming language). For instance, you can write Visual Basic code to interact with a COM object that was created with MFC or ATL. COM+ only cares that you use a tool or programming language that knows how to work with COM. An excellent introduction is available, The COM+ Programming Model Makes it Easy to Write Components in Any Language .
What do ActiveX controls have to do with COM? ActiveX controls, formerly known as OLE controls or OCX controls, are components that can contain one or more objects, and that you can insert into a Web page or application. It's a way to package some bit of functionality, from a simple timer to a full-blown spreadsheet, that you can later reuse elsewhere. And you don't have to be the one who programmed the original control. Because ActiveX controls are implemented via COM, they have methods associated with them that can be called from other applications (EXEs), dynamic link libraries (DLLs), Web pages, or other controls.
The HTML Document Object Model (DOM) is a specification for an object model that is currently a recommendation from the World Wide Consortium (W3C), the cooperative standard-setting body for the World Wide Web. The HTML DOM specifies a standard method to be used to manipulate page elements and create dynamic effects. With this object model, the programmer could access all of the HTML objects on a Web page, and each object would have attributes the programmer could change (such as color or font), as well as methods that could be performed on the element. Microsoft's implementation of the DOM in Internet Explorer 4.0 is consistent with the W3C's recommendation.
Dynamic HTML, a set of technologies that extend HTML, allows the developer access to all elements on the Web page. DHTML, which is supported in Internet Explorer 4.0, also provides you with dynamic styles, dynamic content, Cascading Style Sheets (CSS) positioning, and data binding. The Dynamic HTML Object Model is the method by which you program Dynamic HTML. The DHTML Object Model allows you to manipulate the styles, content, position, and data associated with a particular element on the page.
Now, don't confuse this with the Document Object Model (DOM) described above. DOM is the standard for HTML, whereas DHTML provides a whole set of technologies. Because there's more than one technology involved, you may need to consult the documentation associated with each technology you use. For example, if you are using CSS-positioning, you'll want to consult that documentation rather than the object model documentation.
Extensible Markup Language (XML) provides a generic format to describe different types of data -- anything from spreadsheet data to a purchase order. XML is a simplified subset of Standard Generalized Markup Language (SGML), and was designed specifically for use by Web applications. . . Once the data is packaged up according to the rules of XML, it can be accessed or manipulated via the XML object model. An excellent overview of XML can be found in MSDN Online Web Workshop. Ditto for Charles Heinemann's monthly column, Extreme XML.
XML is now an approved recommendation of the W3C. XML is the basis for the Channel Definition Format (CDF) used by Internet Explorer 4.0 for creating Web channels.
Object models really aren't that difficult a concept. They are the "manual" for using objects. Now that you understand what they are, you can start to understand how controls work and how to work with them.
But we'll let that go for another day....
Developer-technology writer Nancy Cluts knows to beware of geeks bearing GIFs.
For technical how-to questions, check in with the Web Men Talking, MSDN Online's answer pair.