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 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)
Look at the Wikipedia article on abstraction in Computer Science. In particular, you are probably interested in abstraction with respect to object-oriented programming. I've quoted part of the relevant section below:
In object-oriented programming theory, abstraction involves the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system. The term encapsulation refers to the hiding of state details, but extending the concept of data type from earlier programming languages to associate behavior most strongly with the data, and standardizing the way that different data types interact, is the beginning of abstraction. When abstraction proceeds into the operations defined, enabling objects of different types to be substituted, it is called polymorphism. When it proceeds in the opposite direction, inside the types or classes, structuring them to simplify a complex set of relationships, it is called delegation or inheritance.
Generally, I would say that interfaces AND classes should be examples of abstractions, dealing with the data as a conceptual "thing" rather than raw data. Encapsulation is used to make these abstractions work well with other abstractions of conceptually different "things."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With