lundi 12 mars 2018

The pattern name for "instance variable to local variable"

This coding pattern "instance variable to local variable" is often useful for simple thread safety.

class SomeClass
{
    public int SomeNumber { get; set; } = 42;

    public ReturnValue UseSomeNumber(...)
    {
        int someNumberCopy = this.SomeNumber;
        if (someNumberCopy > ...)
        {
            // ... do some work with someNumberCopy
        }
        else
        {
            // ... do something else with someNumberCopy
        }
    }
}

(Excerpted from C# Copying instance variable to local variable in functions of same class, modified private field to public property.)

Does this pattern have a short name?

I think it's hard to understand at a glance without any comments, but also hard to write explanatory comments on all of the occurrences of this pattern.

I just want to write the name of the pattern to say "Google it", but I couldn't find any appropriate simple word.

Aucun commentaire:

Enregistrer un commentaire