ben2ong2
Quality Poster
Paid
Hero Member
   
Reputation: 17
Offline
Gender: 
Posts: 2374
9976.80 RD$
View Inventory
Send Money to ben2ong2
|
 |
« on: October 07, 2006, 08:46:53 AM » |
|
[ Taken from the C++ FAQ. -adc ]
Q70: What's the big deal of separating interface from implementation?
A: Separating interface from implementation is a key to reusable software. Interfaces are a company's most valuable resources. Designing an interface takes longer than whipping together a concrete class which fulfills that interface. Furthermore interfaces require the resources of more expensive people (for better and worse, most companies separate `designers' from `coders'). Since they're so valuable, they should be protected from being tarnished by data structures and other artifacts of the implementation (any data structures you put in a class can never be `revoked' by a derived class, which is why you want to `separate' the interface from the implementation).
Q71: How do I separate interface from implementation in C++ (like Modula-2)?
A: Short answer: use an ABC (see next question for what an ABC is).
Q72: What is an ABC (`abstract base class')?
A: An ABC corresponds to an abstract concept. If you asked a Mechanic if he repaired Vehicles, he'd probably wonder what *kind* of Vehicle you had in mind. Chances are he doesn't repair space shuttles, ocean liners, bicycles, and volkswaggon beetles too. The problem is that the term `Vehicle' is an abstract concept; you can't build one until you know what kind of vehicle to build. In C++, you'd make Vehicle be an ABC, with Bicycle, SpaceShuttle, etc, being subclasses (an OceanLiner is-a-kind-of-a Vehicle).
In real-world OOP, ABCs show up all over the place. Technically, an ABC is a class that has one or more pure virtual member functions (see next question). You cannot make an object (instance) of an ABC.
[ ... to be continued ]
|