Lets say I have a Class as;
1)
Lets Just say I modify this class to be;Code:Class MyClass { //Constructor Public MyClass() { } }
2)
***************************Code:Class MyClass { Private MyClass() { } Public Static MyClass Create() { MyClass myInstn = new MyClass(); return myInstn } }
If I were to instantiate MyClass using 1)
MyClass nwObj = new MyClass();
Using option 2)
MyClass nwObj = MyClass.Create();
****************************
My Question is whats the difference between 2) and 1)?
What advanteges would I get by using option 2) ?
Why would sb prefer to use option 2) over option 1) ?
Thanks!




Reply With Quote