Name for this pattern? (Answer: lazy initialization with double-checked locking)

前端 未结 4 1077
谎友^
谎友^ 2021-01-23 02:45

Consider the following code:

public class Foo
{
    private static object _lock = new object();

    public void NameDoesNotMatter()
    {
        if( SomeDataDo         


        
4条回答
  •  不知归路
    2021-01-23 03:22

    The only name that comes to mind for this kind of is "Faulting". This name is used in iOS Core-Data framework to similar effect.

    Basically, your method NameDoesNotMatter is a fault, and whenever someone invokes it, it results in the object to get populated or initialized.

    See http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFaultingUniquing.html for more details on how this design pattern is used.

提交回复
热议问题