10.1 Assignment

Overview

10.1 Assignment

More Generics

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.

Prepare Molly’s Movers
1.Download the start code for the Molly's Movers assignment

MollysMovers.zip

MollysMovers.zip
A Download the start code for the Molly's Movers assignment
Create specialized moving businesses with generics
Acceptance Criteria
Acceptance criteria
  • MovingBusiness<T> constrains T to IMover and stores its available movers as List<T>.
  • MoveObject checks for an available first mover, asks CanMove, moves a compatible object, and removes that mover after use; an unavailable or incompatible mover produces a clear message.
  • MakeMovingBusiness<T> requires IMover and new(), constructs the requested number of movers, and returns a MovingBusiness<T>.
  • Main creates separate ToyDumpTruck, MovingCrew, and Crane businesses and routes pebbles, dressers, and boulders to the appropriate business.
Instructions
2.Molly is looking to split up her business, as Molly's Movers is becoming too large to manage as one business. She ideally…

Molly is looking to split up her business, as Molly's Movers is becoming too large to manage as one business. She ideally wants to split the business into 3 parts - a crane moving business, a furniture moving business, and a toy dump truck moving business for her kid.

A We could solve this by creating new sub classes - a CraneMovingBusiness, a FurnitureMovingBusiness, and a…

We could solve this by creating new sub classes - a CraneMovingBusiness, a FurnitureMovingBusiness, and a ToyDumpTruckMovingBusiness - but this can be a lot of extra work, and if Molly plans to extend her business further, we'd have to create additional moving business classes. Instead, a better solution for this would be using generics.

1 Make the MovingBusiness class generic

Modify the MovingBusiness class to utilize a single generic type, adding a constraint (where) to ensure that the type passed in is an IMover.

Update the availableMovers list, as well as the list in the constructor to use the new generic type T.

Remove the foreach loop in the MoveObject method, keeping the inner if statement. Also remove the boolean moved, and the if (moved) statement from the method.

Update the if statement to check there are any movers in the list of available movers. Then, inside that if statement, check if the first mover CanMove() the moveable parameter. If it can, have the first mover move the moveable parameter and then remove it from the list of available movers. Otherwise, print a line to the console telling the user we don't have any available movers that can move the object.

2 Update the BusinessFactory

Make the MakeMovingBusiness() method generic

Change the return type to a MovingBusiness<T>

Change the method to accept generic types, with constraints requiring T to be both an IMover, and have a parameterless constructor (new())

Make the List<> of movers accept the generic type instead of IMovers.

Leave only one for loop and have it create numberToCreate new T()'s and add them to the movers list.

Finally, change the return clause, passing in the <T> to the new MovingBusiness object

3 Change how the main method deals with user input

In the Main() method in the Program class, create 3 MovingBusinesses - one for ToyDumpTrucks, one for MovingCrews, and one for Cranes.

Update the case statements to instead use the new appropriate instance of the MovingBusiness class.

4 Ensure the application runs - try moving pebbles, dressers and boulders.
Extend the business to commercial delivery
Acceptance Criteria
Acceptance criteria
  • DeliveryTruck implements the mover contract with lifting capacity 1000 and moving size 10.
  • Package uses weight 1000 and size 10 as specified.
  • The PACKAGE menu option invokes a delivery-truck business and reports the movement result.
Instructions
3.Molly is looking to expand her business into the commercial delivery sector - luckily for us, our MovingBusiness class is…

Molly is looking to expand her business into the commercial delivery sector - luckily for us, our MovingBusiness class is already set up to accept something like this, thanks to generics.

A Create two new classes - DeliveryTruck and Package, and have them inherit/implement as needed
1 DeliveryTruck has a liftingWeight of 1000, and a movingSize of 10.
2 Package has a Weight of 1000, and a size of 10.
B In the Main() method
1 Create a new instance of the MovingBusiness class, using the DeliveryTruck type.
2 Add a new case in the switch statement for "PACKAGE", and use the new MovingBusiness instance to handle it.
3 Update the WriteLine to include Package as an option.
Completion review
4.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.

Create specialized moving businesses with generics Extend the business to commercial delivery