Interfaces

From TBwiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
  
 
For example, a database interface would define member functions to read and write records from a database. Multiple classes deriving from that interface could implement it differently such as using an XML file instead of a real database or storing the information into random access memory (RAM). The benefit from this approach is that any other piece of code in the system only needs to be passed a pointer to the interface regardless of the type of the class implementing it. Thus, there is no knowledge of the actual class implementing the interface.
 
For example, a database interface would define member functions to read and write records from a database. Multiple classes deriving from that interface could implement it differently such as using an XML file instead of a real database or storing the information into random access memory (RAM). The benefit from this approach is that any other piece of code in the system only needs to be passed a pointer to the interface regardless of the type of the class implementing it. Thus, there is no knowledge of the actual class implementing the interface.
 +
 +
 +
** THIS PAGE IS MISSING THE SECTION ON USAGE **

Revision as of 14:54, 7 May 2009

Interfaces are basically a set of member functions that act as an application programming interface (API) to an object. Implemented as pure-virtual base classes (i.e., they can only be used through inheritance), these APIs are used by other modules of the system to interact with all types of objects without knowing their specific definitions (i.e., having to include an header file with the description of the class).

One can see these interfaces as a set of functions that everyone knows how to call. As long as a class inherits from an interface, any object that knows of this interface can use the class. This design approach is commonly used to create systems where the implementation of a given functionality is irrelevant or needs to be replaceable.

For example, a database interface would define member functions to read and write records from a database. Multiple classes deriving from that interface could implement it differently such as using an XML file instead of a real database or storing the information into random access memory (RAM). The benefit from this approach is that any other piece of code in the system only needs to be passed a pointer to the interface regardless of the type of the class implementing it. Thus, there is no knowledge of the actual class implementing the interface.


    • THIS PAGE IS MISSING THE SECTION ON USAGE **
Personal tools