Hello all (OOps! wrote "Hell all" )

just curious to read about the rationale behind this behaviour:
if you have a code in moduleB that inherits from code in moduleA, modularity 
wise the inherited methods behave as if they were invoked from moduleA (not 
from moduleB). see an example at the end of this post.
Naïvely found this behaviour *very bad* but I suppose that if it were not the 
case then the situation could be worse... so I would like to read the rationale 
behind this. 

thanks

code of a service definition in moduleA:
-----------------------------------------------
public abstract class  PropertiesProvider {
        public Properties get(String domain) {
            Class clazz =this.getClass();
            System.out.println(" CLASS " +clazz);
            try {
                Object obj = clazz.getConstructor().newInstance();
                System.out.println("Object " + obj);

            } catch (Exception exc) {
                exc.printStackTrace();
            }
            InputStream is = clazz.getResourceAsStream(domain) ;
            if (is != null) {
                Properties props = new Properties();
                try {
                    props.load(is);
                    return props;
                } catch (IOException e) {
                    System.getLogger("").log(System.Logger.Level.WARNING,e) ;
                }

            }
 and so on ...
now if in module B you just create a Service by inheriting from this class:
 - the className is correct (an instance of the class has been created for the 
service)
- you can't invoke newInstance from that very class!(if the class is not opened 
or exported)
- you can't get the Resource (or other files) unless they are explicilty opened.
if you copy this code in the class implementing the service everything just 
works fine
so there is a difference between the same code being explicitly in the class or 
inherited!
(got a headache trying to find something to say for people learning Java)

Reply via email to