Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of a Static Factory Method, for the this article https://medium.com/@thomaspoignant/static-factory-methods-59e88d2d737f#.9sxp2fho6
public class RandomLongGenerator {
private final long min;
private final long max;
private RandomIntGenerator(long min, long max) {
this.min = min;
this.max = max;
}
public static RandomLongGenerator between(long max, long min) {
return new RandomLongGenerator(min, max);
}
public static RandomLongGenerator biggerThan(long min) {
return new RandomLongGenerator(min, Long.MAX_VALUE);
}
public static RandomLongGenerator smallerThan(int max) {
return new RandomLongGenerator(Long.MIN_VALUE, max);
}
public int next() {...}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment