582334 TDD-ohjelmointimenetelmä ja koodin suunnittelu (5 op), syksy 2009
582334 TDD programming technique and designing code (5 cr), autumn 2009

Kurssiesittely Luennot Harjoitukset

Exercise 6: Legacy Code. SOLID Principles.

Homework

max 7 points

  1. Read articles about each of the SOLID principles so that you will know what they are about. After that, look for violations of the SOLID principles from code that you have written. You may look for violations from code written during or before this course. Take the codes that violate these principles with you to the exercise group. Print at least some of the violations on paper (a couple of sheets of paper) so that this exercise would be easier to handle in the exercise group.

    The original SOLID principle articles (SRP, OCP, LSP, ISP, DIP) are on the page http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod (it's worth having a look at also the package principles: REP, CCP, CRP, ADP, SDP, SAP). You may get an overview of them by listening to the Hanselminutes #145 podcast where each of the principles is explained. The lecture notes for lecture 9 have also more links.

    1 point: You have read and understood all the five SOLID principles.
    2 points: You have found from your codes a violation of one SOLID principle.
    3 points: You have found from your codes violations of three different SOLID principles.

  2. Write tests for the (exceptionally ugly) legacy code in this project. This program called Sorsastus knows how to measure source code metrics and do some runtime profiling. You should extract from this program the counting of lines of code into its own reusable class. Refactor the Sorsastus program so that the counting of lines of code (also empty and comment lines) has been moved into its own class, which does not have dependencies to the rest of the program. The Sorsastus program must use this same class, and the behaviour of the program must not be changed.

    Read the article Working Effectively With Legacy Code (PDF) and apply the techniques adviced therein to do this exercise. After you have written some tests, try making small changes to the code under test - if the tests do not detect the change, the test coverings are not complete enough and you must write more tests, before being able to refactor the code safely. The Sorsastus project can be compiled into an executable JAR file with the mvn package command.

    1 point: You have identified the "change points" and the "inflection point" that surrounds them.
    2 points: You have broken the "external and internal dependencies" of the change points, so that it will be possible to write tests for the code. The behaviour of the program has not changed.
    3 points: You have written enough "test coverings" for the change points, so that it will be possible to modify the program safely. The behaviour of the program has not changed.
    4 points: You have refactored the counting of lines of code into its own class, which does not have dependencies to the other parts of the program. The behaviour of the program has not changed.

In the exercise group we will leave course feedback and have a Coding Dojo.


Viimeksi muokattu 01.12.2010 21:04 Copyright © 2009 Esko Luontola