Hi, I have been working on a peice of code for a long time now and I really cant see how to solve the problem. I have gone over what have been tought and I really cant see how I can solve it!
The code I am working on is:
{ /* Instance variables */ public int stockLevel; // The number of items of this product in stock which is updated // by the deliver() and acquire() methods. Objects of other // classes will need to find out its value. public String description; // The name of the product which will be set to a meaningful // string by the constructor, and then never changed. // Objects of other classes will need to find out its value. /** * Constructor for objects of class Product */ public Product(String aDescription) { super(); this.stockLevel = 0; this.description = aDescription; } /* Instance methods */ /** * Reduce the stock level by the value of the argument. * Method presumes availability has already been checked. */ public void deliver(int anAmount) { this.stockLevel = this.stockLevel - anAmount; }
What I need to do is Describe and explain the changes I would make to the code in order to improve its data hiding and aid maintainability.
I have worked long and hard on this and I just cat crack it! For data hiding I was thinking/have been taught (not very far in the course yet) that I can declare the instance variables as private but I dont think this will work as it states within the explanation for the code that objects of other classes will need to find out the values of the instance variables!
for maintainability I have been looking along the lines of reuse of code but im really stuck on this one. not sure if its because ive been racking my brains so hard on the data hiding part as I feel im very close on that.
Please note that I am trying very hard with this and im not just looking for the easy way out. I jst feel that this is by far the best way for me to learn what I need to learn given that I cant answer the question after reading and re-reading the course books!