wood burning stoves*
The moose likes Beginning Java and the fly likes Data hiding problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Data hiding problems" Watch "Data hiding problems" New topic

Data hiding problems

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Data hiding happened when variable in super class and subclass have same name,I want to know what are problems about data hiding?
Matthew Brown

Joined: Apr 06, 2010
Posts: 4344

Well, the biggest problem is that it confuses people, leading to difficult to find bugs (you think you're referring to one variable when in fact you're referring to another).

In real development, though, you should just avoid it. For instance, if you're following the practice of making all member variables private, then they're not visible to the subclass, so the problem never arises.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525

It's also true in "real development" that 'protected' access is a very powerful
and helpful tool to write clean and readable code. So making everything
private doesn't always work out the best. Lots of "sets" and "gets" can really
cloud the code. I have found that careful choice of variable names is a good
answer. And as you say, never-never-never allow hiding to happen.

Jim ...

wood burning stoves
subject: Data hiding problems
Similar Threads
What is encapsulation
can we achieve data hiding withe the help of encapsulation...
Abstraction and Encapsulation
difference between abstraction and encapsulation
custom table model and column model for JTable