Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: maintainability

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    9
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default maintainability

    Hi, I am working on a code and i need to change the code to make it easier to maintain. I have learned about re use of code so im thinking this is the way i shud be looking at the code but I cant seem to find anything to change.

    the code is:

      public class Product 
     {
        /* 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; 
       }
     
     /**
    * Increase the stock level by the value of the argument
    */
    public void acquire(int anAmount)
    {
    this.stockLevel = this.stockLevel + anAmount;
    }
     
    /**
    * Returns a string giving details of the product
    */
    public String productDetails()
    {
    return "Product " + this.description + ": " + this.stockLevel
             + " in stock.";
    } 
    }what I have come up with so far is I will declare

    if someone could help that wud be great.

    Thanks


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: maintainability

    As far as I can tell, there's nothing I can see that needs to be changed for maintainability. I would declare stockLevel private with it's own getter method (looks like you already have the setter methods), and change the method productDetails() to toString(). The reason for using toString() is because then when you want to convert your object to a String representation, it can be done easily (plus, everyone knows about the toString() method, but many people won't want to look through the JavaDoc to find that the productDetails() method is your toString() method).

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    davie (March 11th, 2010)

  4. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: maintainability


  5. The Following User Says Thank You to copeg For This Useful Post:

    davie (March 11th, 2010)

  6. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    9
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: maintainability

    Hi ive looked at the other thread and i still cant see which way to go with this! anyone got any advice?

  7. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: maintainability

    See my post above Maintainability is a very vague term, but I think that should satisfy your professor (if this is for a class).

  8. The Following User Says Thank You to helloworld922 For This Useful Post:

    davie (March 11th, 2010)

Similar Threads

  1. Data hiding and maintainability
    By humdinger in forum Object Oriented Programming
    Replies: 11
    Last Post: December 5th, 2009, 01:10 PM