Click here to Skip to main content
15,885,757 members
Articles / Programming Languages / C#

Using the Chain Of Command Design Pattern Concepts to Perform Validation and Processing of Complex Data

Rate me:
Please Sign up or sign in to vote.
4.75/5 (9 votes)
3 Mar 2011CPOL7 min read 124.4K   861   49  
An article demonstrating the usage of Chain of Command Design Pattern concepts to perform validation and processing of complex data.
using ChainOfCommandExample.Data;
using HarpyEagle.Chain;

/***************************************************************************************
 *  Author: Curt C.
 *  Email : harpyeaglecp@aol.com
 *  
 *  This software is released under the Code Project Open License (CPOL)
 *  See official license description at: http://www.codeproject.com/info/cpol10.aspx
 *  
 * This software is provided AS-IS without any warranty of any kind.
 *  
 *  Modification History:
 *  08/10/2009  curtc    Creation of class for www.codeproject.com example.
 ***************************************************************************************/

namespace ChainOfCommandExample.BankDataValidationHandlers.TransactionHandlers
{
    /// <summary>
    /// Chain handler that checks to see if the supplied account number is a
    /// valid account number in the data store.
    /// </summary>
    public class TransactionAccountNumberValidationHandler : IChainHandler<AccountTransactionData>
    {
        /// <summary>
        /// Method to process the supplied requestData.
        /// </summary>
        /// <param name="requestData">AccountTransactionData object</param>
        /// <returns>
        /// HandlerResult.CHAIN_DATA_NOT_HANDLED (since account transaction handlers ALL receive the data)
        /// </returns>
        /// <exception cref="ChainHandler.ChainHandlerException">
        /// Thrown if the account number is invalid (not found in the data store).
        /// </exception>
        public HandlerResult ProcessRequest(AccountTransactionData requestData)
        {
            if (DataStore.IsAccountNumberValid(requestData.AccountNumber) == false)
                throw new ChainHandlerException("(TransactionAccountNumberValidationHandler) Invalid transaction account number:"+requestData.AccountNumber);

            return HandlerResult.CHAIN_DATA_NOT_HANDLED;
        }
    }
}

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)
United States United States
Senior Software Developer with background history in developing software for both Unix and Windows based systems using a variety of languages and technologies, including: C#, C++, C, and Java.

Comments and Discussions