top | item 37751159

(no title)

TheFattestNinja | 2 years ago

I find myself more and more over the year falling back to creating lots of "getOrCreateX(args)" and I must say I still haven't found a single scenario where this is worse than "get" and "create":

1) It helps with encapsculation of race conditions (you don't need to acquire locks outside to do if(get==null) { create } when you can have it in the function itself)

2) I normally don't care in my code if this is a pre-existing instance or one that I just created. I just want it now to use.

I personally find this approach superior to CQS.

discuss

order

No comments yet.