小编Tor*_*var的帖子

获取或创建对象的方法有什么好名字?

假设您有一个缓存,以及一个将执行以下操作的方法:

if (wanted Foo is not in cache)
    cache.Add(new Foo())
Return Foo from cache
Run Code Online (Sandbox Code Playgroud)

你会怎么称呼这种方法?GetFoo(),GetOrCreateFoo()还是其他什么东西(更好)?或者这真的应该分为两种方法吗?

naming-conventions

47
推荐指数
6
解决办法
1万
查看次数

标签 统计

naming-conventions ×1