...
Wiki Markup |
---|
Preferring static factory methods over {{public}} or {{protected}} constructors also helps limit class extensibility. \[[Bloch 08|java:AA. Java References#Bloch 08]\]. Typically, a {{private}} constructor is explicitly provided to override the default no-argument {{public}} constructor. |
Code Block |
---|
|
class BankOperation {
private BankOperation() {
// ...
}
public static void factoryMethod() {
// ...
}
}
|
...
A third solution is to provide a non-empty private
constructor accessible only from within the class.
Code Block |
---|
|
class BankOperation {
private BankOperation() {
// ...
}
}
|
...