SWEA 2026 Weekplan 4

The learning goals for Week 38 are:

Mon: Mandatory Hints for Strategy Wed: State Pattern. Maintainability and Flexibility (Lectures). Clean Code (Screencasted only).

Literature:

Slides:

Notes for this weekplan:

Monday lecture (starting 9.15) will cover hints for mandatory, the Strategy exercises.

The Wednesday lectures will cover the State Pattern and discuss Maintability.

The topic of Clean Code is the main topic of this week, but will purely be based upon screencasts. The theory and practices will be exemplified through my refactoring/cleaning up of the HotStone 'attackCard(...)' method. You may study the StandardGame.java yourself before watching the screencasts. The reason for not doing the clean code lectures live is that A) it is a complex code base so refactoring it live easily goes wrong and B) it allows you to skip repetitious tasks like session 'doing more bail out fast'.

The Clean Code presentations consist of

  1. Session 0 / Clean Code slides (62min) (same as the 'W4-1' screencast above)
  2. ... on to the actual live coding, presented in the following sessions:
  3. Session 1 / Do not repeat yourself (14 min)
  4. Session 2 / Bail out fast (6 min)
  5. Session 3 / Bail out fast continued (optional to view) (6 min)
  6. Session 4 / Do one thing (7 min)
  7. Session 5 / One level of abstraction (6 min)
  8. Session 6 / One level of abstraction (12 min)
  9. Session 7 / Do the same thing (1 min)

Links to the Clean Code Classification Template

  1. Clean Code template (excel)
  2. Clean Code template (pdf)

Kata

Spend the first 15-20 minutes of the TØ/Lab class in plenum discussing...

AlphaStone and BetaStone vary with respect to determining who wins the game: In Alpha, Findus always wins after eight turns, while in Beta, the winner is the one whose opponent hero's health reaches zero or less. As a Strategy pattern dictates that the winner algorithm is in another object distinct from the Game object there obviously must be passed information back and forth between the Game and the Strategy.

Discuss benefits and liabilities of choosing each of these viable ways of passing parameters from Game to the Strategy algorithm:

  1. passing: turnCount, findus' hero's health, peddersen's hero's health (all integers)
  2. passing: game object (type: interface Game)
  3. passing: game object (type: class StandardGame/GameImpl)
  4. passing: a Record type containing a copy of all game state (turn count, player in turn, heroes' data (mana, health, power used), fields' contents (all cards and their values), etc.)

One of these options will be the lesser choice if case we invent future strategies for determining the winner based on other criterias. Which one?

Optional Exercises:

These are optional exercises. Be sure to solve the mandatory project first, and only if you have a lot of spare time, try having a look at the exercises below.

Find Dirty Code

Find some code from previous courses or projects, and analyze them according to the Uncle Bob+Henrik principles. If in the mood - clean them up.

Exam Rehearsal

Rehearse a clean code exam situation. Spend 20-25 minutes to prepare a 10 minute oral presentation of an exercise in the example exam question set: demo-question-2025.pdf.

Next, do a 10 minute presentation at the whiteboard in front of your team.

The team provides constructive feedback on the presentation: Is your presentation clear and understandable, do you discuss the concepts and terms correctly, is you Java example code correct, etc. Swap and ensure all in the team gets a chance to rehearse the situation.