The Interface

Started by sukishan, Aug 13, 2009, 01:00 PM

Previous topic - Next topic

sukishan

Thus far, we've been using the word "interface" pretty loosely. My dictionary (1947 American College Dictionary) defines an interface as follows:

"Interface, n. a surface regarded as the common boundary of two bodies or surfaces"

That's actually a useful general description. In COM "interface" has a very specific meaning. COM interfaces are a completely new concept, not available in C++. The concept of an interface is initially hard to understand for many people. An interface is a ghostlike entity that never has a concrete existence. It's sort of like an abstract class - but not exactly.

At its simplest, an interface is nothing but a named collection of functions. In C++, a class (using this terminology) is allowed only one interface. The member functions of that interface are all the public member functions of the class. In other words, the interface is the publicly visible part of the class. In C++ there is almost no distinction between an interface and a class. Here's an example C++ class:


class yyy {
public:
   int DoThis();
private:
   void Helper1();
   int count;
   int x,y,z;
};


When someone tries to use this class, they only have access to the public members. (For the moment we're ignoring protected members and inheritance.) They can't call Helper1, or use any of the private variables. To the consumer of this class, the definition looks like this:


class yyy {
   int DoThis();
};


This public subset of the class is the 'interface' to the outside world. Essentially the interface hides the guts of the class from the consumer.

This C++ analogy only goes so far. A COM interface is not a C++ class. COM interfaces and classes have their own special set of rules and conventions.

COM allows a coclass (COM class) to have multiple interfaces, each interface having its own name and its own collection of functions. The reason for this feature is to allow for more complex and functional objects. This is another concept that is alien to C++. (Perhaps multiple interfaces could be envisioned as a union of two class definitions - something that isn't allowed in C++.)
A good beginning makes a good ending

abelart

The interface is a cross-border, two independent systems meet and take action or communicate with each other. In computer technology, there are main two types of interfaces.

- User interface
- Software interface