Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class variable shadowing

 
Keith Lockey
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

don't understand the purpose of class variable shadowing?? What other types of shadowing are there. Can there be methods shadowing as well??
 
Thomas Thomas
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think if u view it from an object oriented perspective rather than variables and methods. The best way to manipulate variables is through method interfaces. Thats what encapsulation is all about. In java methods matching in signature r overrided not shadowed.
I hope i was answering your question.
Thanks
Thomas
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can lead you into very confusing and potentially buggy places. Say you have a bunch of methods on sh and sh2 that reference i.
sh thing1 = new sh();
sh2 thing2 = new sh2();
thing2.methodOnSh(); // this will use the i on sh
thing2.methodOnSh2(); // this wlil use the i on sh2
Confused? Then the short answer is Don't Do That! (Seen Terminater 3 yet?) Overload and override methods for good OO fun, but I've never had a reason to shadow variables. Anybody else?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic