Is there a naming convention for method that returns completely a brand new object?

999 Views Asked by At

Is there a naming convention for method that returns completely a brand new object?

"Generate" ? "Create" ?

3

There are 3 best solutions below

2
On

There is any public Microsoft recommended convention for that.

4
On

It can be Create as @David suggested, or GetNew - like GetNewProduct(). I prefer GetNew, because Create is more used in factory methods, GetSomething for plain objects, and then GetNewSomething to emphasize that actually a new object is being created.

0
On

Bar bar Foo.barFactory(); is often one used. if Bar is an interface, the exact Bar can be picked by Foo's barFactory,

https://en.wikipedia.org/wiki/Factory_method_pattern