-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Long Mai
committed
May 2, 2011
1 parent
83c7bed
commit e1be047
Showing
12 changed files
with
133 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,13 @@ | ||
| ||
using System; | ||
namespace StarbuzzCoffee | ||
{ | ||
abstract class Beverage | ||
{ | ||
public abstract string Description { get; } | ||
public abstract decimal Cost { get; } | ||
protected decimal CondimentCost | ||
public override string ToString() | ||
{ | ||
get | ||
{ | ||
Decimal condimentCost = 0; | ||
|
||
if(milk) | ||
condimentCost += milkCost; | ||
if(soy) | ||
condimentCost += soyCost; | ||
if(mocha) | ||
condimentCost += mochaCost; | ||
if(whip) | ||
condimentCost += whipCost; | ||
|
||
return condimentCost; | ||
} | ||
return Description + " $" + Cost; | ||
} | ||
|
||
private bool milk = false; | ||
private bool soy = false; | ||
private bool mocha = false; | ||
private bool whip = false; | ||
|
||
private decimal milkCost = 0.49M; | ||
private decimal soyCost = 0.25M; | ||
private decimal mochaCost = 1.00M; | ||
private decimal whipCost = 0.89M; | ||
|
||
public bool Milk { get { return milk; } set { milk = value; } } | ||
public bool Soy { get { return soy; } set { soy = value; } } | ||
public bool Mocha { get { return mocha; } set { mocha = value; } } | ||
public bool Whip { get { return whip; } set { whip = value; } } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/StarbuzzCoffee/StarbuzzCoffee/Condiments/CondimentDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
| ||
namespace StarbuzzCoffee.Condiments | ||
{ | ||
abstract class CondimentDecorator : Beverage | ||
{ | ||
protected readonly Beverage decoratedBeverage; | ||
|
||
protected CondimentDecorator(Beverage beverage) | ||
{ | ||
this.decoratedBeverage = beverage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
namespace StarbuzzCoffee.Condiments | ||
{ | ||
class Milk : CondimentDecorator | ||
{ | ||
private readonly decimal cost = 0.49M; | ||
|
||
public Milk(Beverage beverage) : base(beverage) { } | ||
|
||
public override string Description | ||
{ | ||
get { return base.decoratedBeverage.Description + ", milk"; } | ||
} | ||
|
||
public override decimal Cost | ||
{ | ||
get { return base.decoratedBeverage.Cost + cost; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
namespace StarbuzzCoffee.Condiments | ||
{ | ||
class Mocha : CondimentDecorator | ||
{ | ||
private readonly decimal cost = 1.00M; | ||
|
||
public Mocha(Beverage beverage) : base(beverage) { } | ||
|
||
public override string Description | ||
{ | ||
get { return base.decoratedBeverage.Description + ", mocha"; } | ||
} | ||
|
||
public override decimal Cost | ||
{ | ||
get { return base.decoratedBeverage.Cost + cost; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
namespace StarbuzzCoffee.Condiments | ||
{ | ||
class Soy : CondimentDecorator | ||
{ | ||
private readonly decimal cost = 0.25M; | ||
|
||
public Soy(Beverage beverage) : base(beverage) { } | ||
|
||
public override string Description | ||
{ | ||
get { return base.decoratedBeverage.Description + ", soy"; } | ||
} | ||
|
||
public override decimal Cost | ||
{ | ||
get { return base.decoratedBeverage.Cost + cost; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
namespace StarbuzzCoffee.Condiments | ||
{ | ||
class Whip : CondimentDecorator | ||
{ | ||
private readonly decimal cost = 0.89M; | ||
|
||
public Whip(Beverage beverage) : base(beverage) { } | ||
|
||
public override string Description | ||
{ | ||
get { return base.decoratedBeverage.Description + ", whip"; } | ||
} | ||
|
||
public override decimal Cost | ||
{ | ||
get { return base.decoratedBeverage.Cost + cost; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using StarbuzzCoffee.Condiments; | ||
|
||
namespace StarbuzzCoffee | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
PrintEspresso(); | ||
PrintDarkRoastDoubleMochaWhip(); | ||
PrintHouseBlendSoyMochaWhip(); | ||
} | ||
|
||
private static void PrintHouseBlendSoyMochaWhip() | ||
{ | ||
Beverage beverage = new HouseBlend(); | ||
beverage = new Soy(beverage); | ||
beverage = new Mocha(beverage); | ||
beverage = new Whip(beverage); | ||
Console.Out.WriteLine(beverage); | ||
} | ||
|
||
private static void PrintDarkRoastDoubleMochaWhip() | ||
{ | ||
Beverage beverage = new DarkRoast(); | ||
beverage = new Mocha(beverage); | ||
beverage = new Mocha(beverage); | ||
beverage = new Whip(beverage); | ||
Console.Out.WriteLine(beverage); | ||
} | ||
|
||
private static void PrintEspresso() | ||
{ | ||
Beverage beverage = new Espresso(); | ||
Console.Out.WriteLine(beverage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters