“GetOrCreate” - does that idiom have an established name?

后端 未结 5 1281
清歌不尽
清歌不尽 2021-02-12 19:51

Ok, consider this common idiom that most of us have used many times (I assume):

class FooBarDictionary
{
    private Dictionary fooBars;

          


        
5条回答
  •  失恋的感觉
    2021-02-12 20:27

    It sort of depends why you're doing it - the idiom is one I've seen be called memoization, caching, initialisation on demand, create on first use. Normally I call the method "ensureFoo" rather than "GetOrCreate"

提交回复
热议问题