• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data hiding problems

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Data hiding happened when variable in super class and subclass have same name,I want to know what are problems about data hiding?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matthew,

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 ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic