Click here to Skip to main content
15,886,258 members
Articles / Programming Languages / C# 4.0

Propagator in C# - An Alternative to the Observer Design Pattern

Rate me:
Please Sign up or sign in to vote.
4.94/5 (19 votes)
13 Jul 2009CPOL9 min read 55.7K   368   53  
Re-usable implementation of the Propagator Design Pattern in C#, a potentially more powerful alternative to the well-known Observer Design Pattern.
// Martijn Boeker, July 14, 2009
// License: The Code Project Open License (CPOL) 1.02

using MB.Propagators;

namespace PropagatorDemo
{
    /// <summary>
    /// Example class with propagator.
    /// </summary>
    public class ClassWithPropagator
    {
        /// <summary>
        /// Propagator object.
        /// </summary>
        private Propagator _propagator = new Propagator("SimpleExample");

        /// <summary>
        /// Constructor.
        /// </summary>
        public ClassWithPropagator()
        {
        }

        /// <summary>
        /// Propagator.
        /// </summary>
        public IPropagator Propagator
        {
            get
            {
                return _propagator;
            }
        }
    }

    /// <summary>
    /// Examples for the article.
    /// </summary>
    class Examples
    {
        public void Bidirectional()
        {
            IPropagator propagatorA = new Propagator();
            IPropagator propagatorB = new Propagator();
            propagatorA.AddDependent(propagatorB, true);
        }

        public static void LinkClassWithPropagator()
        {
            ClassWithPropagator p1 = new ClassWithPropagator();
            ClassWithPropagator p2 = new ClassWithPropagator();
            p1.Propagator.AddDependent(p2.Propagator, true);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Phi International
Canada Canada
Grew up in Amsterdam, now living in downtown Vancouver. There are definitely more mountains here.

My first internship was with the first company in the Netherlands to teach C++ (www.datasim.nl). During this internship I got to know Object Oriented Design, which kept my interest until this day. In the mean time, I have worked for different companies in the Netherlands and Canada. I have done most of my recent work in C#, developing Database/Web/Desktop applications.

I am currently working as a freelance Software Developer for PHI International in Amsterdam.

The CodeProject rocks!

Comments and Discussions