Using factory patterns, using example simple in Java