Geeks With Blogs
.net alternatives by Michel Grootjans

I recently got the opportunity to teach a 3 day course on the subject of "Principles, Patterns and Practices in .net". I must say it was a fun and enriching experience. I have never taught a course before, so I decided to go off the beaten path and do a little experiment in format. No need to copy existing formats that can be found everywhere else in Belgium.



I took the excellent Head First Design Patterns as a guide to run through each pattern in the same way: - show an existing implementation without using a pattern; discuss the problems with the current design - a change in the requirement is introduced that will be hard to implement - refactor the existing implementation to a pattern - apply the change in requirement - discuss the applied solution - explore some alternatives - try to give an appropriate name to the applied solution After each pattern was explained, shown and discussed, I drew a summary of the pattern on a flip-chart. These were then hung to the wall as information radiators. During later discussions, each pattern could be compared to other patterns, because easy reminders were constantly visible. A nice tool for this is 3M's self-stick flip-charts. You just draw, and hang them on the wall. During the explaining phase, the same principles kept coming up (depend upon abstractions, encapsulate what varies, open/closed, ...). These were also added to a list on the wall as they came up. Every time we looked at a new design, these principles were used to criticize code.



The subject of design patterns is a vast one. I had to limit the content of the course, since I had only three days. You must also take into account that the human brain has not been made to absorb a lot of knowledge in a small amount of time after you graduate ;-). So I decided not only to show the most important design patterns, but to add a few related exercises to allow everyone to take on a more active role from time to time. The first day, after lunch, we did a coding dojo for about an hour. The subject I choose was the bowling game kata. This small exercise during a course on design patterns was a deliberate choice. First of all, a coding dojo loosens the atmosphere by being more informal and fun. Second, every participant got five minutes to add a significant part to the code. So no one was able to fall asleep. Third, this exercise got the message across that you don't have to reach for patterns to have a good solution. The best solution is almost always the easiest one. The second day, after lunch, I showed the team a demo of how IoC containers and AoP can solve some of the problems they're having right now. Since I seem to be a .net dinosaur, I still use, and that's exactly what I demoed. The third day, I tried a refactoring exercise. Lets look at a piece of existing code, criticize it and try to make it better. The choice of the example was easy. Martin Fowler's book on refactoring has a great one. Small enough to keep the timing, large enough to introduce a few more common refactorings.


Source code

Since everyone on the team was already using SVN for source control, I decided to host the course code on google projects. I made a trunk where all the unmodified code is stored, and a branch with all the modifications/refactorings we made during the course. Before each break, I committed the current state of the code. This allows every participant to review each piece of code "before" and "after" patternization whenever they have time for it.


Course material

An issue I discussed with the customer prior to starting the course was documentation. What will the participants take away from these three days? I could have written a bunch of word documents explaining each and every design patter in detail, together with diagrams and examples. I explained that this would be a pointless exercise for me, and a useless tool for the participants. I proposed to just buy the Head First book, as this is a course material of much higher value than anything I could ever produce.


Evaluation of progress

Being an agilist, I couldn't refrain from applying agile ideas to this course. On the first day, I let the team enumerate all the patterns they had ever heard of. Lucky for me, these were all patterns that I prepared. I wrote them all down on yellow stickies, and put them in the "ToDo" section of the whiteboard. I counted the number of patterns hanging there and drew a burndown: 3 days on the x-axis, 13 patterns to go on the y-axis. Every time that a pattern was over, I moved the pattern to the "Done" section. At every break, I updated the burndown. This allowed us to evaluate our progress, and decide to touch on particular problems the team was having with existing projects. At the end of each day, we also held a small retrospective. This allowed me to fine-tune my teaching method or speed. All in all, it was a great experience. I enjoyed it tremendously, and I believe the participants did too.

Posted on Monday, June 28, 2010 11:03 PM .net , Personal | Back to top

Comments on this post: Teaching Principles, Patterns and Practices in .net

# re: Teaching Principles, Patterns and Practices in .net
Requesting Gravatar...
I hope you don't mind, but I can never resist the urge to refactor. Here is how I would further refactor the ChildrensPrice class. :)

public class ChildrensPrice : IPrice
private const int RenterPoints = 1;
private const int OverdueAfterDays = 3;
private const double OverdueDailyCharge = 1.5;
private const double BasePrice = 1.5;

public double GetCharge(int daysRented)
// I really didn't like the thisAmount variable name here!
var charge = BasePrice;
if (IsOverdue(daysRented))
charge += CalculateOverdueCharge(daysRented);
return charge;

public int GetFrequentRenterPoints(int daysRented)
return RenterPoints;

private bool IsOverdue(int daysRented)
return daysRented > OverdueAfterDays;

private double CalculateOverdueCharge(int daysRented)
return (daysRented - OverdueAfterDays) * OverdueDailyCharge;

I also feel that Movie.CreatePrice() should belong in a separate class; perhaps a BasePrice class?

Anyway I hope you don't mind. Looks like you had a good class! I like the agile aspect of how you ran it. I might borrow that in the future.
Left by Ryan on Jun 29, 2010 6:03 AM

# re: Teaching Principles, Patterns and Practices in .net
Requesting Gravatar...

I agree with your example. The points you are making were discussed, but not implemented.

This was however an exercise in refactoring in the context of a course on design patterns. 3 days is a short period of time to cover the patterns I intended to show. A topic for a future course might be "clean code".
Left by Michel Grootjans on Jun 29, 2010 8:18 AM

Your comment:
 (will show your gravatar)

Copyright © Michel Grootjans | Powered by: