I am confused about abstraction and encapsulation.What i feel is that class is encapsulation as it encapsulates data and behaviour,while interface is abstraction.Please comment
I am confused about abstraction and encapsulation.What i feel is that class is encapsulation
Share
I think your terminology is confused.
Encapsulation – puts related data and functionality in one place. We can get this through classes
Polymorphism – Allows values of different data types to be handled using a uniform interface.
Polymorphism can be achieved by inheriting base classes (with virtual functions) and/or by implementing interfaces.
These techniques (and others) give us abstraction, which really applies to any of the processes we use to break a problem up into smaller components.
EDIT
Q) You ask “Can i say,abstraction is the topmost hierarchy which is accomplished through encapsulation and polymorphism?”
A) I can’t answer that question, I don’t know what you mean by “topmost” and “highest”.
There is no hierarchy here.
Functional Decomposition is a form of abstraction, it can be achieved without using Object Orientation, where should it come in the hierarchy?
The best I can do with a hierarchy is this definition (straight out of my own head, so YMMV)
breaking a large problem into
smaller components, so each smaller
problem can be worked on in
(relative) isolation.
use to achieve abstraction. It
involves identifying different types
of data and behavior that can be
treated in an homogeneous manner.
behaviour, encapsulating the
behaviour in a type. It provides no
actual behaviour or data
behaviour, but may also provide
behaviour and data, all encapsulated
in a type.
as providing a simpler or purer
form of polymorphism than abstract
classes.