1 of 28

If-parsing connect activity

  • The image shows what this activity might look like in Miro or Mural
  • The solutions are on the next slide
  • The text is in the slide notes

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

2 of 28

If-parsing connect activity - solutions

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

3 of 28

Lift Up Conditional: Learning Hour

  • This deck has been created to provide useful resources for anyone presenting the “Lift Up Conditional” learning hour
  • The main web page summarising this learning hour can be found on the Samman site here: [INSERT LINK]

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

4 of 28

Lift Up Conditional

Situation:

  • Entangled if statements�

Strategy:

  • For each condition:
  • Duplicate entangled code inside if..else
  • Simplify all contained conditions�

Result:

  • A switch statement with a separate case for each condition

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

5 of 28

The next slide shows the Gilded Rose C# code before and after using the lift-up conditional technique

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

6 of 28

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

7 of 28

The next two slides give a simple visual explanation of the technique

  • If you are planning to dedicate only one hour to this activity, I suggest you use one of these in preference over the more detailed explanation that follows, as the detailed version will probably take too long.

Lift up conditional

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

8 of 28

Simple schematic for sharing

9 of 28

Simple schematic for sharing – includes end state

10 of 28

The next set of slides give a more detailed visual explanation of the technique

  • If you are planning to dedicate more than one hour to this activity, you can take the time to use these. Otherwise I suggest you use one of the simpler schematics in previous slides, as the detailed version will probably take too long.

Lift up conditional

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

11 of 28

Starting point

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

12 of 28

END RESULT Part 1 - Tidied if statement

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

13 of 28

END RESULT Part 2 - Switch statement (ready for polymorphism)

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

14 of 28

STEP 1 - Duplicate nasty code inside if..else

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

15 of 28

STEP 2 - Replace relevant conditions with true / false

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

16 of 28

STEP 3 - Remove falses

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

17 of 28

STEP 4 - Remove unnecessary conditions

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

18 of 28

BACK TO STEP 1 - Duplicate code inside if..else

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

19 of 28

STEP 2 - Replace relevant conditions with true / false

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

20 of 28

STEP 3 - Remove falses

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

21 of 28

STEP 4 - Remove unnecessary conditions

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

22 of 28

Start again. STEP 1 - Duplicate nasty code inside if..else

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

23 of 28

STEP 2 - Replace relevant conditions with true/false

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

24 of 28

STEP 3 - Remove falses

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

25 of 28

STEP 4 - Remove unnecessary conditions

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

26 of 28

END RESULT Part 1 - Tidied if statement

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

27 of 28

END RESULT Part 2 - Switch statement (ready for polymorphism)

License: CC-BY-SA-4.0. Attribution: Clare Sudbery and sammancoaching.org

28 of 28

Text