mercredi 4 février 2015

Decorator Pattern: WIll not run

I am trying to implement the Decorator pattern, but I keep getting an error when I try to run my program. I cannot figure out why. I know it has something to with something not being an interface, but I have tried a bunch of changes and nothing is working. I appreciate any assistance!



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OODAssignment3_ZackDavidson
{
class Program
{
static void Main(string[] args)
{
//Creates a new Calvin Klein Shirt fordecoration
CalvinKlein ckShirt = new CalvinKlein();
Console.WriteLine(Convert.ToString(ckShirt.GetBrand()));

//Puts a solid color on the Calvin Klein Shirt
solidColorDecorator ckSCD = new solidColorDecorator(ckShirt);

//Puts stripes on the Calvin Klein Shirt
stripedShirtDecorator ckSSD = new stripedShirtDecorator(ckShirt);

//Puts a pocket on the Clavin Klein Shirt
pocketShirtDecorator ckPSD = new pocketShirtDecorator(ckShirt);

//Creates a new Tommy Hilfiger Shirt
TommyHilfiger thShirt = new TommyHilfiger();

//Puts stripes on the Tommy Hilfiger Shirt
stripedShirtDecorator thSSD = new stripedShirtDecorator(thShirt);

//Puts a pocket on the Tommy Hilfiger Shirt
pocketShirtDecorator thPSD = new pocketShirtDecorator(thShirt);
}//EndOfMain
}//EndOfClassProgram

public abstract class ShirtsComponent
{
public abstract string GetBrand();
public abstract double GetPrice();
}

class CalvinKlein : ShirtsComponent
{
private string ck_Brand = "Calvin Klein";
private double ck_Price = 75.0;

public override string GetBrand()
{
return ck_Brand;
}

public override double GetPrice()
{
return ck_Price;
}
}

class TommyHilfiger : ShirtsComponent
{
private string th_Brand = "Tommy Hilfiger";
private double th_price = 85.0;

public override string GetBrand()
{
return th_Brand;
}

public override double GetPrice()
{
return th_price;
}
}

public abstract class Decorator : ShirtsComponent
{
ShirtsComponent fashion_Base = null;

protected string _brand = "Undefined Decorator";
protected double _price = 0.0;

protected Decorator(ShirtsComponent fashionBase)
{
fashion_Base = fashionBase;
}

#region ShirtsComponent Members

string ShirtsComponent.GetBrand()
{
return string.Format("{0}, {1}", fashion_Base.GetBrand(), _brand);
}

double ShirtsComponent.GetPrice()
{
return _price + fashion_Base.GetPrice();
}
#endregion
}

class solidColorDecorator : Decorator
{
public solidColorDecorator(ShirtsComponent fashionBase)
: base(fashionBase)
{
this._brand = "Solid Color Shirt";
this._price = 25.0;
}
}

class stripedShirtDecorator : Decorator
{
public stripedShirtDecorator(ShirtsComponent fashionBase)
: base(fashionBase)
{
this._brand = "Striped Shirt";
this._price = 50.0;
}
}

class pocketShirtDecorator : Decorator
{
public pocketShirtDecorator(ShirtsComponent fashionBase)
: base(fashionBase)
{
this._brand = "Dotted Shirt";
this._price = 90.0;
}
}


}//EndOfNamespace


Aucun commentaire:

Enregistrer un commentaire