Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 13 Jul 2009
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

namespace MB.Propagators
{   
    /// <summary>
    /// Interface for updating objects in a dependency network. 
    /// </summary>
    public interface IPropagator
    {
        /// <summary>
        /// Process state change: update this propagator to the given state and notify dependents.
        /// </summary>
        /// <param name="stateChange">Object containing information about state change.</param>
        void Process(StateChange stateChange);

        /// <summary>
        /// Process state change.
        /// </summary>
        /// <param name="stateChange">Object containing information about state change.</param>
        /// <param name="options">Indicates how state message should be processed.</param>
        void Process(StateChange stateChange, StateChangeOptions options);

        /// <summary>
        /// Process state change.
        /// </summary>
        /// <param name="stateChange">Object containing information about state change.</param>
        /// <param name="options">Indicates how state message should be processed.</param>
        /// <param name="sender">Propagator who propagated the command, may be null. The command will not be sent in the direction of the sender.</param>
        void Process(StateChange stateChange, StateChangeOptions options, IPropagator sender);
               
        /// <summary>
        /// Add propagator as dependent.
        /// </summary>
        /// <param name="dependent">Propagator to add.</param>
        /// <param name="biDirectional">If true, dependency will be bi-directional.</param>
        void AddDependent(IPropagator dependent, bool biDirectional);

        /// <summary>
        /// Remove propagator as dependent.
        /// </summary>
        /// <param name="dependent">Propagator to remove.</param>
        /// <param name="biDirectional">If true, dependency will be removed in both directions.</param>
        void RemoveDependent(IPropagator dependent, bool biDirectional);

        /// <summary>
        /// Remove all dependents.
        /// </summary>
        /// <param name="biDirectional">If true, dependencies will be removed in both directions.</param>
        void RemoveAllDependents(bool biDirectional);
    }
}

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)

About the Author

Martijn Boeker
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!

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 14 Jul 2009
Article Copyright 2009 by Martijn Boeker
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid