8.1 Adapter Pattern Lab

Overview

8.1 Adapter Pattern Lab

This assignment is based off Head First Designs p. 235-270

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.1 Adapter LastName.zip

8.1 Adapter LastName.zip
A Download and extract the start code.
Run the application. The Console should print out the behavior of the mallard duck.
Acceptance Criteria
Acceptance criteria
  • The specified behavior or explanation is demonstrated using the detailed tasks below.
Instructions
2.Run the application. The Console should print out the behavior of the mallard duck.
A Run the application. The Console should print out the behavior of the mallard duck.
Import the TurkeyService.
Acceptance Criteria
Acceptance criteria
  • The completed implementation satisfies this requirement: Write a line to the Console about testing the turkey.
  • The completed implementation satisfies this requirement: Call Fly and Gobble on the wildTurkey object.
Instructions
3.Import the TurkeyService.

Some animal enthusiast organization has asked that you incorporate their Turkey library and use them as ducks.

A Right-click on the References in your project and select 'Add Reference...'
B On the bottom right, click 'Browse...' and select the TurkeyService.dll from the zip provided.
C In the MainWindow after instantiating the MallardDuck...
1 Instantiate a WildTurkey object named wildTurkey after the MallardDuck.

You will need to add a using for TurkeyService.

2 Write a line to the Console about testing the turkey.
3 Call Fly and Gobble on the wildTurkey object.
4 Write out an extra line for spacing.
5 Write a line to the Console about testing the duck.
D Check Your Work:
1 Run the application. Your output should look like the output below.
Console: Output for 8.1 Adapter Pattern Lab. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Console: Output
Line 11: : Testing the turkey. . .
Line 2turkey. . .
Line 2: : I'm flying a short distance.
Line 3'm flying a short distance.
Line 3: : Gobble gobble
Line 4Line 4:
:
Line 55: : Testing the duck. . .
Line 6duck. . .
Line 6: : I'm flying
Line 7'm flying
Line 7: : Quack
Build an adapter.
Acceptance Criteria
Acceptance criteria
  • The completed implementation satisfies this requirement: Remove the lines of code that call the turkey's Fly and Gobble methods.
  • Duck exposes the required contract: Fly(); Quack().
  • TurkeyAdapter exposes the required contract: TurkeyAdapter(turkey: ITurkey); Fly() override; Quack() override.
  • ITurkey exposes the required contract: Fly(); Gobble().
Instructions
4.Build an adapter.
A Try and test the turkey.
1 Remove the lines of code that call the turkey's Fly and Gobble methods.
2 Instead, call TestDuck and pass in the wildTurkey.

This isn't possible because TestDuck only takes IDuck types.

3 F12 on WildTurkey. You can't change anything about the class so no help there.
4 Remove the call to TestDuck.
B Add a TurkeyAdapter class based on the diagram below.
Class Diagram: TurkeyAdapter; Members and relationships are shown in the editable reference; unrelated members may be omitted.
Class Diagram: TurkeyAdapter
  • New
  • Changed
  • Removed
Class: Duck
Methods
+ Fly()
+ Quack()
Class: TurkeyAdapter
Inherits from Duck
Fields
- turkey : : Turkey
Methods
+ TurkeyAdapter(ITurkey turkey)
+ Fly<override>
+ Quack()<override>
Interface ITurkey
Methods
Fly()
Gobble()Methods
+ TurkeyAdapter(ITurkey turkey)
+ Fly<override>
+ Quack()<override>
Interface ITurkey
Methods
Fly()
Gobble()
C In the TurkeyAdapter class...
1 Assign the turkey field to the turkey parameter in the constructor.
2 In the Quack method, call the turkey's Gobble method.
3 In the Fly method, write a for loop that calls the turkey's Fly method 5 times.
D In the Main method after the line that prints out about testing the turkey....
1 Instantiate a new TurkeyAdapter object named turkeyDuck and pass in the wildTurkey object to the constructor.
2 Call TestDuck and pass in the turkeyDuck.
E Check Your Work:
1 Run the application. Your output should look like the output below.
Output: Adapter Output for 8.1 Adapter Pattern Lab. Use the adjacent task instructions to identify the required controls, output, or debugger values.
Output: Adapter Output
Line 11: : Testing the turkey. . .
Line 2turkey. . .
Line 2: : I'm flying a short distance.
Line 3'm flying a short distance.
Line 3: : I'm flying a short distance.
Line 4'm flying a short distance.
Line 4: : I'm flying a short distance.
Line 5'm flying a short distance.
Line 5: : I'm flying a short distance.
Line 6'm flying a short distance.
Line 6: : I'm flying a short distance.
Line 7'm flying a short distance.
Line 7: : Gobble gobble
Line 8Line 8:
:
Line 99: : Testing the duck. . .
Line 10duck. . .
Line 10: : I'm flying
Line 11'm flying
Line 11: : Quack
Zip up your assignment and turn it in to Canvas.
5.Zip up your assignment and turn it in to Canvas.
A Zip up your assignment and turn it in to Canvas.
Completion review
6.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.

Run the application. The Console should print out the behavior of the mallard duck. Import the TurkeyService. Build an adapter.