What is the "Dispatcher" design pattern?

Posted by Ben Farmer on Stack Overflow See other posts from Stack Overflow or by Ben Farmer
Published on 2010-03-17T20:14:57Z Indexed on 2010/03/17 20:31 UTC
Read the original article Hit count: 309

Filed under:
|
|
|

What is the "dispatcher" pattern and how would I implement it in code?

I have a property bag of generic objects and would like to have the retrieval delegated to a generic method.

Currently, I have properties looking for a specific key in the bag. For example:

private Dictionary<String, Object> Foo { get; set; }
private const String WidgetKey = "WIDGETKEY";

public Widget? WidgetItem
{
    get
    {
        return Foo.ContainsKey(WidgetKey) ? Foo[WidgetKey] as Widget: null;
    }
    set
    {
        if (Foo.ContainsKey(WidgetKey))
            Foo[WidgetKey] = value;
        else
            Foo.Add(WidgetKey, value);
    }
}

It was suggested that this could be more generic with the "dispatcher" pattern, but I've been unable to find a good description or example.

I'm looking for a more generic way to handle the property bag store/retrieve.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about design-patterns