Why do you need nothing but getXXX() . Any method that has and / or means that it does a lot and mixes problems and seriously violates the Single Responsibility Principle .
If the caller really cares whether the object is created on demand, if all they need from the contract is to get the object?
getOrCreate implies that the get or object will be created but not returned.
Again, why should I worry about the create part?
If I really have to take care, would getOrCreateAndGet be semantically correct, but extremely unorthodox and prone to discussions with peers about methods that do many things, and mixing problems and breaking the Single Responsiblity Principle ? Just because other people call things ambitious and insensitive, it is not a good excuse to do it wrong.
source share