Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encapsulation & Abstraction

 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pankaj vijay wrote:
i am very confused between Encapsulation & Abstraction & Data Hiding.... they all seems like same...
as per my knowledge encapsulation means containing many thing like fields members in an object is encapsulation
Hiding inner working form user is abstraction. while not showing field to the user is Data Hiding...
but am i right???


When you encapsulate something you get an inside and an outside. The outside is data abstraction and the inside is information hiding. Encapsulation concerns how strong this division is, that is to what extent you can poke inside from the outside.

The main encapsulation unit in Java is the class. In principle everything that's exposed to the outside, namely all non-private members, constitute the data abstraction. Hidden inside is the implementation.

An interface is a pure data abstraction.

In object orientation data abstraction manifests itself as user defined types (a type is what you declare variables to be of). Information hiding is the ability to hide information as private members of a class (an enum in Java is a specialized class). So data abstraction is when you define types using the class, interface and enum facilities of Java.

Encapsulation is the ability to separate the what from the how. That is the type (the abstract outside) from how it works inside (a concrete hidden implementation). Encapsulation also is related to questions of mutability/immutability, that is to what extent and how well the inside is isolated from the outside.
 
pankaj vijay
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii

i am very confused between Encapsulation & Abstraction & Data Hiding.... they all seems like same...
as per my knowledge encapsulation means containing many thing like fields members in an object is encapsulation
Hiding inner working form user is abstraction. while not showing field to the user is Data Hiding...
but am i right???
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has finally happened. I posted so fast that my reply arrived before the OP asked the question.
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pankaj vijay,

They both involve information hiding but in different ways. I was taught that encapsulation is information hiding in class files, so other programmers can't learn the inter-workings of the class. This way they can't break your code or call a method that's meant to be private. I don't want other programmers calling setXXX() from their code. By making your instance variables and methods private, your code is safe. Abstraction in programming languages is like this. High Level programming (Java, C) is an abstraction of low level programming (x386, MIPS) in that a lot of the code required in low level programming has already been written and hidden to the programmer. Instead of writing:



in low level, it's simply



in high level. The details are hidden to make the coding easier. The abstract modifier in Java indicates that a class is a general or "base" class that can be implemented in various ways.
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uj nossnahoj wrote:It has finally happened. I posted so fast that my reply arrived before the OP asked the question.

How can that happen
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijitha Kumara wrote:
How can that happen


Well, we must've travelled through a time warp. Or maybe it has something to do with daylight saving time that confused the forum software?
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, Admins will have to take a look at this (not sure whether this has happened before).
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
double posted
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've reported the issue to our team of sheriffs. Let's see if they can find out what happened here.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first two posts definitely occurred at the right time to be affected by the DST change, if the server is in the Mountain Time Zone. Probably pankaj vijay's post was at 0737 GMT, and uj's was at 0816 GMT. In Mountain Time these are 1:37 MDT (before the switch), and 1:16 AM MST (after the switch). If the forum software sorts using Mountain Time, and does not include MDT/MST info in the string being sorted, that would account for what we see here.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uj nossnahoj wrote:It has finally happened. I posted so fast that my reply arrived before the OP asked the question.

The times are still unordered (we think that's due to daylight savings time changing), but at least the posts are in the right order.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic