Help is needed. The super-class method from the child is not called.
About code:
This code is a few warehouses that accept some products, and when the NoIceboxWarehouse full (9 stores as much as possible), then all the products go to NoIceboxReserveWarehouse . It’s not worth paying attention to the Warehouse itself since it was created when the conditions that the warehouse might overflow did not exist. And here I just have to add such an extension so that it becomes possible, but so that the old tests do not break.
I have several classes in the inheritance chain. I am trying to call the parent method from the child:
Parental:
public class Warehouse implements Repo { /** * List contain products. */ protected ArrayList<Product> products = new ArrayList<>(); @Override public ArrayList<Product> getProducts() { return this.products; } @Override public String getName() { return "warehouse"; } @Override public boolean isAppropriate(Product product) { return (product.checkQuality() < 26); } } Here is his heir:
public class NoIceboxWarehouse extends Warehouse { /** * This repo contain only 9 products, all next after 9, go in NoIceboxReserveWarehouse. * @return "" if filling equal 10 products. */ @Override public boolean isAppropriate(Product product) { return this.products.size() < 9 && (product.checkQuality() < 26) && this.checkIceFlag(product); } private boolean checkIceFlag(Product product) { return !product.getFlag().equals("ice") && !product.getFlag().equals("canReproduce"); } } And another level:
public class NoIceboxReserveWarehouse extends NoIceboxWarehouse { @Override public String getName() { return "NoIceboxReserveWarehouse"; } /** * Check base repo reached the limit. * @param product product for check. * @return result base repo limit and product quality. */ @Override public boolean isAppropriate(Product product) { // вот тут проблема: // >>return super.getProducts.size() > 8<< ... return ControlQuality.getNoIceboxWarehouse().getProducts() .size() > 8 && (product.checkQuality() < 26); } } In the last class in the isAppropriate(Product product) method isAppropriate(Product product) I want to check the status of the parent NoIceboxWarehouse object NoIceboxWarehouse such a record (I have it commented in the code): super.getProduct.size() > 8 but all the time I get zeroes have to go to the class that stores these repositories create static pointers and pull state on them:
ControlQuality.getNoIceboxWarehouse().getProducts().size() > 8 I want to do something more sophisticated but something doesn't work, why is super not working? Is it because he doesn't know what specific copy I mean?
Can I somehow get access to the class field without referring to the place where the object of this class is created, through inheritance or something else? Here help please advice that I do not understand?