|
Community Opinion/Answers
Abstraction vs. Encapsulation - Principles of Object Oriented Programming (OOPS):
Abstraction
In order to process something from the real world we have to extract the essential characteristics of that object.
Data abstraction can be viewed as the process of refining away the unimportant details of an object, so that only the useful characteristics that define it remain. Evidently, this is task specific.
Encapsulation
Encapsulation is one step beyond abstraction. Whilst abstraction involves reducing a real world entity to its essential defining characteristics, encapsulation extends this idea by also modeling and linking the functionality of that entity. Encapsulation links the data to the operations that can be performed upon the data.
OOP makes use of encapsulation to enforce the integrity of a type (i.e. to make sure data is used in an appropriate manner) by preventing programmers from accessing data in a non-intended manner
Through encapsulation, only a predetermined group of functions can access the data. The collective term for datatypes and operations (methods) bundled together with access restrictions (public/private, etc.) is a class.
|
anirudh girey (anirudhgirey@gmail.com)
Said..
encapsulation is wrraping up of a data into single unit and abstraction is hidding unnesecary background details and representing only important and essential detail
Encapsulation protects abstractions. Encapsulation is the bodyguard; abstraction is the VIP. Encapsulation provides the explicit boundary between an object's abstract interface (its abstraction) and its internal implementation details. Encapsulation puts the implementation details "in a capsule." Encapsulation tells users which features are stable, permanent services of the object and which features are implementation details that are subject to change without notice. Encapsulation helps the developers of an abstraction: it provides the freedom to implement the abstraction in any way consistent with the interface. (Encapsulation tells developers exactly what users can and cannot access.) Encapsulation also helps the users of an abstraction: it provides protection by preventing dependence on volatile implementation details. Abstraction provides business value; encapsulation "protects" these abstractions. If a developer provides a good abstraction, users won't be tempted to peek at the object's internal mechanisms. Encapsulation is simply a safety featur
|
Ari
Said..
Encapsulation is defined as the process of wrapping up the data members and member functions together into a single unit.It is dependent on the object data type. Abstraction is the process of eliminating unnecessary details thereby highlighting the important features.It is independent of the object data type.
A real world example, consider u have setup a big building(say a company), the details regarding materials used to built (glass, bricks), type of work, manager of the company, number of floors, design of the building, cost of the building etc. can be classified as ABSTRACTION. Whereas, type of glass or bricks(grey one or red one) used, who all work for which all departments n how they work, cost of each and every element in the building etc. comes under Data ENCAPSULATION. Another example can be of a VIP(Abstraction) and his assistant(Encapsulation).
Abstraction-outer layout, used in terms of design Encapsulation-inner layout, used in terms of implementation.
|
savio sequeira
Said..
abstraction is showing only essential details. encapsulation is hiding the working of abstraction in a class or template.
|
pawan V Tak
Said..
Abstraction: tecnically abstraction is like use of methods in a class by creating a object of that class, and u no need to know how the these methods are defined and worked.
Encapsulation: And in encapsulation keep code and data it manipulates safe from the outside code,i.e it work like a wrapper for the inside code.
|
Madhu N
Said..
Encapsulation: Writing up of data and functions into a Single unit is referred is "Encapsulation"
|
Ams
Said..
Encapsulation is nothing but showing only those things which are required by wrapping up complexity & hence it is also called that it leads to data hiding but its not data hiding. Never say its data hiding… so never say its data hiding, its wrapping up complexity in one capsule that is class & hence Encapsulation… While abstraction denotes the essential characteristics of an object which differentiates from other kinds of object...
Abstraction is achieved by making class abstract having one or more methods abstract. Which is nothing but essential characteristic which should be implemented by the class extending it. e.g. when you inventing/designing a car you define a characteristics like car should have 4 doors, break, steering wheel etc… so anyone uses this design should include this characteristics. Implementation is not the head each of abstraction. It will just define characteristics which should be included.
Encapsulation is achieved keeping data and the behaviour in one capsule that is class & by making use of access modifiers like public, private, protected along with inheritance, aggregation or composition. So you only show only required things, that too, only to the extent you want to show. i.e. public, protected, friendly & private ka funda…… e.g. GM decides to use the abstracted design of car above. But they have various products having the same characteristics & doing almost same functionality. So they write a class which extends the above abstract class. It says how gear box should work, how break should work, how steering wheel should work. Then all the products just use this common functionality. They need not know how the gear box works or break works or steering wheal works. Indivisual product can surely have more features like a/c or auto lock etc…..
Both are powerful; but using abstraction require more skills than encapsulation and bigger applications/products can not survive with out abstraction.
|
rakesh
Said..
encapsulation :- hiding all internal details and and ultimately showing the only one unit.......... ex:- if we take a car, the internal parts like carburetter,spark ignite,power oil,base frame,suspension,etc...... hiding all this parts and showing only a car.........
nice example na im telling this example because im mechanical engg..... and working in IT field
abstraction :- reducing the complexity of the real world and showing it in understandable manner
any thing wrong or queries please do mail me. rocyyoung06@gmail.com
|
Sakthivel.S
Said..
Encapsulation: ---------------------- Encapsualation is basically, wrapping up of data memebers and methods. As you said, You hide the data for security such as making the variables as private, and expose the property to access the private data which would be public. So, when you access the property you can validate the data and set it.
Example:
Class Demo { private int _mark;
public int Mark { get { return _mark; } set { if (_mark > 0) _mark = value; else _mark = 0; } } }
Abstraction:- ------------------ Abstraction have the methods which will be common for all the derived class would need. It contains the skeletion which needs to be implemented by the derived class also, which will be declared as abstract method.
Example:
abstract class CurryBase { public abstract void doCurryMasala(); }
public class FishCurry : CurryBase { public void doCurryMasala() { // Add Fish Curry specific contents also. } }
|
Dev Said..
Abstraction - Abstraction is the process of hiding the working style of a method. Encapsulation - Encapsulation is the binding member data and member function and hiding data from the outside function or method.
|
mukesh Said..
hi, Thanks Ams the explanation was very good that cleared my basic concepts.
|
NAGARAJUGURRAM Said..
hello, Encapsulation is the process of hiding internal implementation of the class and restricting to access directly that data and can be able to access through publicly exposed methods(getters & setters..).
Abstraction is the process of hiding or removing the insufficient data and force to implement sufficient implementation for a class or method.....
|
praveen Said..
Enough is is Enough I must say none of you do not understand the concepts
no matter what post you hold your basics are not clear
|
anirudh girey Said..
here we go for more example hope this will help u guys to understand the concept:-
There are three types of oops in java. 1.Encapsulation:Encapsulation is mechanism,that binds together data and code its manipulates. Ex:suppose we are writing one bean.we declaring two private variables.we are providing setters and getters methods of two variables.These variables are accessed in that class. 2.Inheritance:To acquire the base class properties into derived class. Ex:class A{ m1(){ System.out.println("m1 method"); } } class B extends A{ m2(){ System.out.println("m2 method"); } public static void main(String args[]){ B b = new B(); System.out.println(b.m1); System.out.println(b.m2); } } O/p is:m1 method m2 method. Polymorphism:one Interface to be used for a general class of actions. There are two types of polymorphisms. 1.Compile-time polymorphism:what object will be assigned to the present variable.This will be evaluated at compile time. This is known as compile-time polymorphism. 2.Run-time polymorphism:what object will be assigned to the present variable.This will be evaluated at runtime depending on condition.This is known as Run-time polymorphism.
|
komal garg
Said..
the wrapping of data and method in yo a single unit called is encapsulation
abstraction refer to act of representing essential feature without including the background details............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
AMRIT ANAND
Said..
Data abstraction:-Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the unwanted charteristics of that situation or object ENCAPSULATION:- it is the process of binding of data and function into a single unit
|
Priyanka Sharma
Said..
Please see/visit below link for more OOps concepts details. here you can find all details with real world example with other dot net tutorials such as asp.net, C#, JavaScript and SQL server
http://www.expertsblog.in/category/OOPs-Concepts-.aspx
|
C. Punitha
Said..
A mechanism that prevents the data of a particular objects safe from intentional or accidental misuse by external functions is called "data Encapsulation"
The act of representing essential features without including the background details or explanations is known as "data abstraction"
|
naveen shekhar
Said..
Data abstraction:-Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the unwanted charteristics of that situation or object Encapsulation is the process of hiding internal implementation of the class and restricting to access directly that data and can be able to access through publicly exposed methods(getters & setters..).
|
|
|
master of oops
Said..
dear guys read this carefully
What is the difference between abstraction and encapsulation?
Data abstraction:-Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the unwanted charteristics of that situation or object Encapsulation is the process of hiding internal implementation of the class and restricting to access directly that data and can be able to access through publicly exposed methods
thank you
best of luck
|
midhun
Said..
fuck off nerds...........................................................................................................................................................................................FUCK U BITCH ASSHOLES.....................................................................................................................................................................................................................................................................................................................................................................................................................................
|
Alexander From KIU
Said..
abstraction deals with hiding details and exposing only particular concept or object
Encapsulated deals with ability of an object to be a container for related properties and methods that is function Programs written in older languages did not enforce any property.
|
Kaushal Chandu(NIIT,Dwarka-6)
Said..
Abstraction It is not necessary that you know the working of every part of the computer.Even without hardware knowledge, you can perform many tasks on the computer. Abstraction does not mean that information is unavailable. Abstraction means to show only the necessary details of an entity.
Encapsulation Encapsulation means the act of enclosing one and more items of an entity..
|
Ankit(NIIT,Dwarka-6)
Said..
NIIT wale kuch nahi padhate...............................................................................................................................................................................................................................................................................................................................
|
Ushasi Bharti Vinita
Said..
Ye dosti hum nahi todenge.. Ladenge har din magar khana nahi chhodenge..... ........ ....... @#$$#!#$$$..... ..... ---------------- ============== +++++++++++++++ ------------------------------------------------------- --------------------------------------------- ................................ ...................................................... ....................................................
|
Ankit(NIIT,Student#: S121075700335)
Said..
Paise kha liye NIIT ne.. Kuchh nahi padhate.. ................ .............................. .............................................. ..................................................... ................................................................ .......................................................... .................................................. ............................................ ................................. ......................
|
A. Shinde
Said..
Abstraction --- To hide the internal details and provide what can be done. Encapsulation---To bind data with data members and provide how can be done
Suppose u r building Customer class having different members like customer name , Customer Account no, eligibility of Customer, Customer balance etc
so when some one ask for customer eligibility then it simply provide it. so that goes under abstraction.
and how that eligibility is calculated that goes under Encapsulation.
so here encapsulation protect abstraction.
|
srinu
Said..
Encapsulation Encapsulation means the act of enclosing one and more items of an entity..
Data abstraction:-Abstraction is the process of recognizing and focusing on important characteristics of a situation or object and leaving/filtering out the unwanted charteristics of that situation or object Encapsulation is the process of hiding internal implementation of the class and restricting to access directly that data and can be able to access through publicly exposed methods
|
kamlesh kumar yadav
Said..
encapsulationand abstraction is hidding unnesecary background details and representing only important and essential detail encasulation is wrraping up of a data into single unit Encapsulation is defined as the process of wrapping up the data members and member functions together into a single unit.It is dependent on the object data type. Abstraction is the process of eliminating unnecessary details thereby highlighting the important features.It is independent of the object data type.
|
Syed Danish haider
Said..
EnsU£ation is wraping of data in appropriate manner such as c£asS functions in order.whi£e data abstraction is making data hidden from real world to protect that data and unwanted things...EnsU£ation is wraping of data in appropriate manner such as c£asS functions in order.whi£e data abstraction is making data hidden from real world to protect that data and unwanted things...EnsU£ation is wraping of data in appropriate manner such as c£asS functions in order.whi£e data abstraction is making data hidden from real world to protect that data and unwanted things...EnsU£ation is wraping of data in appropriate manner such as c£asS functions in order.whi£e data abstraction is making data hidden from real world to protect that data and unwanted things...EnsU£ation is wraping of data in appropriate manner such as c£asS functions in order.whi£e data abstraction is making data hidden from real world to protect that data and unwanted things...
|
sangeetha
Said..
very nice answer. that real time example is easy way to understand me....................................................................................................................................................................................
|
Gokul
Said..
Encapsulation is the process of binding the data and functions together into an single unit.... Ex:cars and owners... all the functions of cars are encapsulated with the owners.. No one else can access it...
Abstraction is the process of providing relevant information by hiding unimportant information... Ex:car vendor providing information related to car
|
tejeswarao
Said..
Encapusulation : Guards the data by using private methods.(ex. Internal Mechanism of Mobile) ................................................................... Abstration : Implementation of encapusulation by using public methods.(ex. External Mechanism of Mobile) .................................................................
|
sdkfj
Said..
kdsjfkjkjksdjfkjsdfl;sDFk:dfgkdf;lgk;ldfkg;lkfdg;k;ldfkg;k;dflkg;kfdg;kdf;lllllllllllllllllllllllgk;dlfkmdv;mkdfm'sadkfldf;kjg'sfjdg'jsadg'jf'jg.xmcv;sd'asssdf;gjf;djkg;mv;dmf;gj;jsd;gj;jf;gj;jf;gsdfdfffffffffffffsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
|
Hirak Mukherjee
Said..
Encapsulation is actually a process of wrapping of data and function together as a unit and this can be made possible by using class members private.
Bidhun fuck off!!Tell yourself a bitch's son and a son of a bisexual father.
|
|
|
|