Click here to Skip to main content
11,487,406 members (71,111 online)
Click here to Skip to main content
Add your own
alternative version

Dynamic Binding Using the Factory Pattern

, 1 Nov 2009 CPOL 11.7K 152 16
Using the Factory design pattern to hide dynamic binding and use configuration strings to determine which classes should be instantiated.
/*************************************************************************
 *
 * Copyright 2009 Richard (Rick) Marvin Wycoff, All Rights Reserved
 * DO NOT ALTER OR REMOVE THIS COPYRIGHT NOTICE.
 *
 * NOTICE: You are permitted to use, modify, and distribute this file in 
 * accordance with the terms of the license agreement accompanying it.  
 * Any existing copyright or authorship information in any given source
 * file must remain intact.
 *
 **************************************************************************/

using Wycoff.Shared;

namespace Wycoff.Client
{
    /// <summary>
    /// An implementation of the ITheService interface.  This represents how
    /// a test program might have its own special implenentation to avoid a
    /// dependency on another service.
    /// </summary>
    public class TheInProcessService : ITheService
    {
        /// <summary>
        /// Salutation
        /// </summary>
        private string _salutation = "Hello";

        /// <summary>
        /// Default Constructor
        /// </summary>
        public TheInProcessService()
        {
        }

        /// <summary>
        /// Constructor with user specified salutation
        /// </summary>
        /// <param name="salutation">
        /// User specified salutation
        /// </param>
        public TheInProcessService(string salutation)
        {
            _salutation = salutation;
        }

        /// <summary>
        /// Implementation of the ITheService interface.
        /// </summary>
        /// <param name="name">
        /// Name of person to which the salution should be addressed.
        /// </param>
        /// <returns>
        /// Complete salutation
        /// </returns>
        public string Hello(string name)
        {
            return string.Format("{0} {1}!", _salutation, name);
        }
    }
}

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)

Share

About the Author

Richard (Rick) Wycoff
Software Developer (Senior)
United States United States
Rick's software passion is developing "invisible” software components, the kind that no one ever thinks about because they just do what they are supposed to do. He believes in standards, design patterns, and designing components for extensibility and reuse.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 1 Nov 2009
Article Copyright 2009 by Richard (Rick) Wycoff
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid