Tutorial by Examples

We can provide a meaningful name for our constructors. We can provide several constructors with the same number and type of parameters, something that as we saw earlier we can’t do with class constructors. public class RandomIntGenerator { private final int min; private final int max; ...
We can avoid providing direct access to resource intensive constructors, like for databases. public class DbConnection { private static final int MAX_CONNS = 100; private static int totalConnections = 0; private static Set<DbConnection> availableConnections = new HashSet<DbConnectio...
The static factory method is a variation of the factory method pattern. It is used to create objects without having to call the constructor yourself. When to use the Static Factory Method if you want to give a meaningfull name to the method that generates your object. if you want to avoid over...

Page 1 of 1