8.2 Decorator Pattern Lab

Overview

8.2 Decorator Pattern Lab

This assignment is based on Head First Designs p.79-105

Work through the stories in order. Use the acceptance criteria to check each feature, and complete the nested tasks using the specified names, values, and scenarios.

Download and extract the start code.
1.Download and extract the start code.

8.2 Decorator LastName.zip

8.2 Decorator LastName.zip

This is a WPF app where a user should be able to select the type of beverage they want and then add whatever condiments they want. Instead of creating many subclasses to instantiate all the combinations, we are going to use the Decorator Pattern.

A Download and extract the start code.
Define a CondimentDecorator class.
Acceptance Criteria
Acceptance criteria
  • The completed implementation satisfies this requirement: Define a new class named CondimentDecorator and put it in the Decorators folder.
  • The completed implementation satisfies this requirement: Have the CondimentDecorator class inherit from Beverage.
  • The completed implementation satisfies this requirement: Make the Cost and Description properties override and abstract with getters and setters.
Instructions
2.Define a CondimentDecorator class.
A Define a new class named CondimentDecorator and put it in the Decorators folder.
B Have the CondimentDecorator class inherit from Beverage.
C Make the Cost and Description properties override and abstract with getters and setters.

This ensure that any class inheriting from this class has their own properties.

In the Milk, Mocha, Soy and Whip classes (ConcreteDecorators):
Acceptance Criteria
Acceptance criteria
  • The completed implementation satisfies this requirement: Inherit from CondimentDecorator.
  • The completed implementation satisfies this requirement: Define properties for Description and Cost that get and set the beverage's Description and Cost.
  • The completed implementation satisfies this requirement: Define a field of type Beverage named beverage.
Instructions
3.In the Milk, Mocha, Soy and Whip classes (ConcreteDecorators):
A Inherit from CondimentDecorator.
B Define properties for Description and Cost that get and set the beverage's Description and Cost.
C Define a field of type Beverage named beverage.
D Define a constructor that assigns the beverage field to the beverage parameter and adds to the Description and Cost. For Example:
public Milk(Beverage beverage)
{
this.beverage = beverage;
this.Description += ", Milk";
this.Cost += .10m;
}
Write the Client code in the MainWindow.
Acceptance Criteria
Acceptance criteria
  • Click the Order button to ensure the message box shows and the application doesn't crash.
  • Select a condiment and click Order. A message should show and the application shouldn't crash.
  • Select a coffee and click Order. The description and price should appear.
  • Select condiments and click Order. The description and price should be updated.
Instructions
4.Write the Client code in the MainWindow.
A Define a private field of type Beverage named beverage.
B In the OrderButton_Click...
1 Assign the beverage field to null.
2 Write an if/else block that checks if each individual radio button's IsChecked property is true. If it is, instantiate the…

Write an if/else block that checks if each individual radio button's IsChecked property is true. If it is, instantiate the beverage field to that type.

Since the return from the IsChecked property is a nullable type (bool?) you have to explicitly check if (IsChecked == true)

C Write if statements for each condiment type that checks if the IsChecked property is true. If it is, assign the beverage…

Write if statements for each condiment type that checks if the IsChecked property is true. If it is, assign the beverage field to a new instance of that condiment and pass in the beverage field.

D Surround the if statements in a try/catch block. In the catch block, show a message about needing to order coffee.
E In a try block, set the descriptionLabel's Content property to the beverage's Description and the priceLabel's Content…

In a try block, set the descriptionLabel's Content property to the beverage's Description and the priceLabel's Content property to the beverage's Cost property.

F In the catch block, show a message box with a message about selecting a coffee to order.
G Check Your Work:
1 Run the application.
2 Click the Order button to ensure the message box shows and the application doesn't crash.
3 Select a condiment and click Order. A message should show and the application shouldn't crash.
4 Select a coffee and click Order. The description and price should appear.
5 Select condiments and click Order. The description and price should be updated.
Completion review
5.Review the feature acceptance criteria
A Confirm the required results

Return to each story and verify its acceptance criteria. Preserve the submission format and destination stated in the activity; a reading, setup guide, lab, video demonstration, and oral final may require different evidence.

Define a CondimentDecorator class. In the Milk, Mocha, Soy and Whip classes (ConcreteDecorators): Write the Client code in the MainWindow.