Static Factory Method
We have often used the constructor when You need to create the object. because This function is basically offered a lot of the programming languages like Java, C++, JS, python and so on. But actually, It is only a basic technique not good thing. We could get a lot of advantage if use the static factory method techniques not the constructor.
The advantages
1. Readability ( You could give the names for these functions. )
1 |
|
If a parameters of Member are more than now, the way using constructor would be difficult to read on the source code.
And If the most of parameter types are number then It’s also too hard to read those.
2. Immutability. ( You could create the java object on singleton pattern. )
The constructor should create the new one whenever you use that although you don’t need it.
1 |
|
A constructor always use with ‘new’ keyword so It’ too hard to create the object as the singleton type when you use a constructor way.
We could achieve the immutability attribute like the above way whenever we want to do that.