Re: [General]acces of members of subclass



Daniel Moyne wrote:

So Lew as superclasses cannot acces subclass members (in you example you
just provide methods "bar" in the subclass sub but no members) there is no
reasons to declare them as public and then only private makes sense ; am I
correct ?

Well, I think it's far to strong a statement to say there is "no" reason to declare fields in a sub class public. In fact it's done all the time in the Java API.

What you should say is that you don't see how sub-classing will implement the solution you were hoping for (whatever solution that might be). That's fine. Sub-classing and inheritance is not a panacea in OOD. In fact, you should avoid it and favor composition and concrete classes if possible.

Inheritance is kind of a last resort solution, and getting it correct can be tricky, as you are discovering.





.



Relevant Pages

  • Re: Multiple Inheritance - does order matter?
    ... > When declaring a class that uses multiple inheritance, ... > In my program I use an STL vector to store objects of type Server *. ... > class MyServer: public Server, ... but if I declare it as: ...
    (comp.lang.cpp)
  • Re: final methods and classes
    ... talking about inheritance, not redefinition.) ... If you do not declare a class 'final', then you had better darn well ... make sure that it's conditioned for inheritance. ... The API writer does not predict, he permits. ...
    (comp.lang.java.programmer)
  • Re: final methods and classes
    ... although redefinition (of a method or an ... invariant) by a subclass is the most interesting case here. ... If you do not declare a class 'final', then you had better darn well ... make sure that it's conditioned for inheritance. ...
    (comp.lang.java.programmer)
  • Question about inheritance
    ... I read a tutorial about inheritance (http://java.sun.com/docs/books/ ... declare a field in the subclass with the same name as the one in the ... Or have a "good resource" to ...
    (comp.lang.java.programmer)