Posts

Showing posts from November, 2012

Decorator Pattern

This is an example of the Decorator pattern, in this case a decorator for ObservableCollection.  Working with WPF and ObservableCollection using threads, one will run into the problem whereby the ObservableCollection cannot be updated from outside the owning thread; Delegates and Invoke will not work. A solution is to contain and expand the class, as is done in this example on michIG's Blog.

This linked file contains the original code in C#, as well as the same code converted to VB.NET.

Salient Characteristic(s)
Sets an internal pointer to the decorated object, sending method calls and property actions to the internal objectExtends the object by wrapping it and adding some aspect handled by the decorator
Code

using System;
using System.Collections.ObjectModel;
using System.Windows.Threading;
using System.Collections.Specialized;
using System.ComponentModel;

namespace DesignPatterns
{
    /// <summary>  
    /// This class is an observablecollection which invokes automatically.  
    /// T…