What is the use of this .Net template

I was looking for a template that could provide both a thread-safe and an unsafe version of the same class. The technical aspects of this are pretty obvious. I think I was hoping to find naming conventions and access, etc ....

Therefore, I find this template throughout the "Systems.Collections" namespace:

public class WhatEv
{
    private class SyncWhatEv : WhatEv
    {
        // overrides IsSyncronized = true
        // overrides whatever else to make it thread safe
    }

    public virtual bool IsSynchronized
    {
        get { return false; }  
    } 

    public static WhatEv Synchronized(WhatEv whatEv)
    {
        return new SyncWhatEv(whatEv);
    }
}

There are a number of classes that implement this: HashTable, Queue, ArrayList, Stack, etc. I understand inheritance. But why make it a private, nested class and make the user jump through the hoop to get to it? Are there any advantages to this?

+5
source share
3 answers

. , : MS y'all. , , . , ... .

. .

-1

- (.. Hashtable, Queue) . , , . Synchronized , , .

, . , . "" / .

+3

, @CodeNaked . . , 2 , . SO: # Queue.Synchronized lock() ?

+2

All Articles