Click here to Skip to main content
15,895,423 members
Articles / Programming Languages / C#

An Introduction to Design Patterns using the Decorator Pattern

Rate me:
Please Sign up or sign in to vote.
3.28/5 (32 votes)
3 Jan 20066 min read 125.7K   603   50  
An introduction to the Decorator pattern.
using System;
using System.Collections.Generic;
using System.Text;

namespace Patterns_Decorator
{
    /// <summary>
    /// Provides a concrete implementation of the Leather car option.
    /// </summary>
    class OptionLeather : CarOption
    {
        double _cost = 1000;
        string _description = "Leather Seats, ";
        Car _car;

        public OptionLeather(Car car)
        {
            _car = car;
        }

        public override double Cost
        {
            get
            {
                return _car.Cost + _cost;
            }
        }

        public override string Description
        {
            get
            {
                return _car.Description + _description;
            }
        }
    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Currently, Eric lives in Birmingham, Alabama where he works for EBSCO Industries as Web Developer/Analyst

Comments and Discussions