cxxr / better-java

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

#1 #39

Closed Auraliano closed 8 years ago

Auraliano commented 8 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 8 years ago

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

Auraliano commented 8 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 8 years ago

In Java, everything is an object.

Auraliano commented 8 years ago

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

Hinsteny commented 8 years ago

Maybe we can use 'Optional' in java8!

cxxr commented 8 years ago

It was an example.