Ryan's District
November 22, 2008, 04:07:01 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: You are not allowed to view links.
Register or Login
How to Unlock Nokia mobile Phones

You are not allowed to view links.
Register or Login
Request any TV Show / series / Episodes / movie and we will get it for you for free

 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: C++ tips - Separating interface and implementation, abstract base classes  (Read 1759 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« 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 ]

Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
« on: October 07, 2006, 08:46:53 AM »

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: RAYAN.tv
-

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.804 seconds with 30 queries.

Google visited last this page Today at 03:13:26 PM