Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

But how organize constants when are more than one? With respect to this answerthis answer and this one, it seems the best way to organize them is using Enum:

But how organize constants when are more than one? With respect to this answer and this one, it seems the best way to organize them is using Enum:

But how organize constants when are more than one? With respect to this answer and this one, it seems the best way to organize them is using Enum:

replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

But how organize constants when are more than one? With respect to this answer and this onethis one, it seems the best way to organize them is using Enum:

But how organize constants when are more than one? With respect to this answer and this one, it seems the best way to organize them is using Enum:

But how organize constants when are more than one? With respect to this answer and this one, it seems the best way to organize them is using Enum:

added 974 characters in body
Source Link
hasanghaforian
  • 651
  • 1
  • 6
  • 14

I use eclipse and someSome times I have texts that appears in different places, like comments, messages... For example if I have a custom Exception, probably class doc, messages that passes as parameter to its constructor andwill have the same phrases (here This exception throws under situation1):

/**
 * This exception throws under situation1 ...
 *
 */
public class SomeException extends Exception {

    public static class Builder{
        String message = "This exception throws under situation1. So ... ";

        public Builder(String message) {
            this.message = this.message + "\r\n" + message;
        }
        public SomeException build(){
            return new SomeException(this);
            
        }
    }
    
    private SomeException(String detailMessage) {
        super(detailMessage);
    }

    public SomeException(Builder builder) {
        this(builder.message);
    }
}

And also documents of each method that throw exception will have the same phrases and terms.phrase:

/**
 * @throws SomeException
 *             This exception throws under situation1 ...
 */
private void test() throws SomeException {
    throw new SomeException.Builder("message").build();
}

If I copy/paste phrase, maintenance of documents will be hard (it needs finding and updating all repeats on each edit).

 /**
  * commentexception forthrows CONSTANTunder situation1
  */
public static final String CONSTANT = "comment"exception forthrows CONSTANT";under situation1";
public enum Meta {
    /**
     * commentexception forthrows CONSTANTunder situation1
     */
    CONSTANT("comment"exception forthrows CONSTANT"under situation1");

    private String text;

    Meta(String text) {
        this.text = text;
    }

    public String getText() {
        return this.text;
    }

}

I use eclipse and some times I have texts that appears in different places, like comments, messages... For example if I have a custom Exception, probably class doc, messages that passes as parameter to its constructor and documents of each method that throw exception will have the same phrases and terms. If I copy/paste phrase, maintenance of documents will be hard (it needs finding and updating all repeats on each edit).

 /**
  * comment for CONSTANT
  */
public static final String CONSTANT = "comment for CONSTANT";
public enum Meta {
    /**
     * comment for CONSTANT
     */
    CONSTANT("comment for CONSTANT");

    private String text;

    Meta(String text) {
        this.text = text;
    }

    public String getText() {
        return this.text;
    }

}

Some times I have texts that appears in different places, like comments, messages... For example if I have a custom Exception, probably class doc, messages that passes as parameter to its constructor will have the same phrases (here This exception throws under situation1):

/**
 * This exception throws under situation1 ...
 *
 */
public class SomeException extends Exception {

    public static class Builder{
        String message = "This exception throws under situation1. So ... ";

        public Builder(String message) {
            this.message = this.message + "\r\n" + message;
        }
        public SomeException build(){
            return new SomeException(this);
            
        }
    }
    
    private SomeException(String detailMessage) {
        super(detailMessage);
    }

    public SomeException(Builder builder) {
        this(builder.message);
    }
}

And also documents of each method that throw exception will have the same phrase:

/**
 * @throws SomeException
 *             This exception throws under situation1 ...
 */
private void test() throws SomeException {
    throw new SomeException.Builder("message").build();
}

If I copy/paste phrase, maintenance of documents will be hard (it needs finding and updating all repeats on each edit).

 /**
  * exception throws under situation1
  */
public static final String CONSTANT = "exception throws under situation1";
public enum Meta {
    /**
     * exception throws under situation1
     */
    CONSTANT("exception throws under situation1");

    private String text;

    Meta(String text) {
        this.text = text;
    }

    public String getText() {
        return this.text;
    }

}
added 22 characters in body
Source Link
hasanghaforian
  • 651
  • 1
  • 6
  • 14
Loading
Correct spacing around puncation and indentation of javadocs.
Source Link
user40980
user40980
Loading
added 201 characters in body
Source Link
hasanghaforian
  • 651
  • 1
  • 6
  • 14
Loading
Rollback to Revision 2
Source Link
Mike Partridge
  • 6.7k
  • 1
  • 26
  • 40
Loading
removed comments
Source Link
Mike Partridge
  • 6.7k
  • 1
  • 26
  • 40
Loading
edited body
Source Link
user22815
user22815
Loading
Source Link
hasanghaforian
  • 651
  • 1
  • 6
  • 14
Loading