cxxr / better-java

Resources for writing modern Java
Other
5.79k stars 729 forks source link

#1 #39

Closed Auraliano closed 9 years ago

Auraliano commented 9 years ago

public class DataHolder { public final String data;

public DataHolder(String data) {
    this.data = data;
}

}

If it has many properties , create many construct method ? it similar to use get()/set() way

Ghost141 commented 9 years ago

Then you probably should consider the builder pattern. https://github.com/cxxr/better-java#the-builder-pattern

Auraliano commented 9 years ago

Builder pattern can resolve this question,But If it only has one attribute, why do you need to create a class?

cxxr commented 9 years ago

In Java, everything is an object.

Auraliano commented 9 years ago

If a class includes only one string attribute ,Why not use string directly?

Hinsteny commented 9 years ago

Maybe we can use 'Optional' in java8!

cxxr commented 9 years ago

It was an example.