0

i'm not sure if this has been asked before. I've got a class that has all of the variables i want to use in my project(30 fields) and i have many other classes based on it, however, i want to disable specific getters in some and specific setters in others. I'm currently thinking about overriding each setter/getter for each field manually and setting return to null or something like that, but that'd still show the getter/setter, which isn't supposed to happen.

If you have any insights please let me know.

Yash
  • 97
  • 1
  • 11
  • `final` helps to restrict access of parent methods into child. – bNd Feb 03 '16 at 11:04
  • @bmt yes i'm aware of final, but that would have to be in the parent class, and my restrictions are going to be completely different from one child class to another. If i misunderstood, please elaborate on your idea. – Yash Feb 03 '16 at 11:27
  • here u use override syntax plz elobrate what do u mean by overriding? – bNd Feb 03 '16 at 11:28
  • 1
    Not sure I understand correctly, but if you want only some subclasses to be able to access getters/settters, then you're going about it the wrong way. Sure it would be possible to write something like protected getVal(){ if(this instanceof someSubclass) return val; else return null; } but that's just poor design. – dsp_user Feb 03 '16 at 11:56

0 Answers0