Interfaces

From TBwiki
(Difference between revisions)
Jump to: navigation, search
Ktrueman (Talk | contribs)
(New page: Interfaces are basically a set of member functions that act as an API to an object. Implemented as pure-virtual base classes (i.e. can only be used through inheritance), these APIs are use...)
Newer edit →

Revision as of 13:49, 7 May 2009

Interfaces are basically a set of member functions that act as an API to an object. Implemented as pure-virtual base classes (i.e. 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 everybody knows how to call. As long as a class inherits from an interface, any object that knows this interface can use the class. This design approach is commonly use to create systems where the implementation of a specific functionality is irrelevant or need 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 RAM. The benefit from this is that any other piece of code in the system only need 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.

Personal tools