Java- Wrapping a function in another class function -


i want check if java code oop enough,

say have class called shop , inside class have method called getaverageearnings

i have class called simulator , inside have wrapper function wrap shop class getaverageearnings

i have hide shop class user.

eg:

public class shop{    public double getaverage(){      return (this.total/5);    } }  public class simulator{     shop shop;     public simulator(){       shop = new shop();    }     public double getaverage(){        return shop.getaverage();    } } 

is practice or bad practice in terms of oop-ness?

as far understand question is, want call method of shop class simulator class don't want shop involve in outer world. right.

if case, suggest follow below steps design module.

i) declare shop abstract, because have tightly coupled logic in , create protected method getaverage.

ii) extend shop in simulator or fragment class , call getaverage supper method.

hope help.


Comments