views:

41

answers:

2

How would you help a newbie to grasp the idea of abstraction? Anybody know a suitable illustration?

A: 

This link should give you the information on abstraction and encapsulation. hope you know basic C++. http://www.learncpp.com/cpp-tutorial/84-access-functions-and-encapsulation/

It explains on the power of encapsulation using a simple variable name change example.

ckv
@ckv It's actually not for myself...
Gulshan
So what you can aswell read the article and explain it if u like to others or whoever
ckv
I think, the remote control example is very much right. But how this concept is implemented in programming is not that much clear. And IMHO encapsulation and abstraction are not exactly same thing.
Gulshan
A: 
  1. Find two problems that have similar solutions. They could be two programs that do something similar, e.g. count the number of matching items in a collection (but with different collection types).
  2. Explain why it's inefficient to solve each one separately. (E.g. inefficient to write two different programs.)
  3. Extract the part that the two solutions have in common. (E.g. a function that matches an item; something that increments a counter; something that iterates over a collection.)
  4. Show how that this common part is an abstraction of each of the originals. Abstractions hide details. (E.g. An algorithm that iterates over any collection, applies the matcher, and increments the counter as appropriate.)

You've extracted the common part, but the point where the abstraction really comes into play is the interface where it touches the specific instance (or implementation).

  1. Discuss the various techniques of finding the right interface. There are often multiple ways of extracting the common part, each results in a different shaped interface. If you then reuse the common part in a third solution, you then discover that some interfaces are more apt than others.
Edmund