A few months ago I finished reading the second edition of Brad Abrams and Krzysztof Cwalina’s excellent Framework Design Guidelines book. I just love how this book condenses the lessons learned in building the .Net Framework in areas such as design patterns and API usability into a set of easy to follow guidelines annotated by various luminaries from Microsoft and beyond.
For me reading the book provided valuable insight into .Net, reinforced my knowledge of design patterns and provided lots of useful advice on software engineering in general. As an example one guideline that I recall as I write this is “do prefer protected accessibility over public accessibility for virtual members”. This leads to the suggestion of applying the template method pattern as follows:
public Control {
public void SetBounds(...)
{
...
SetBoundsCore(...);
}
protected virtual void SetBoundsCore(...) { ... }
}
The book also makes the valuable point that this pattern allows the base class to enforce that overloads remain semantically consistent by defining them in the base class in terms of one core virtual method that can then be overridden.
On the usability front a comment from Krzysztof has stuck with me since reading the book:
The number of customers that will use your API is inversely proportional to the number of new statements in your simple scenarios.
This reinforces the book’s suggestion of a scenario driven design approach where we are encouraged to write code for common scenarios before designing the API and run user studies early on with other developers writing code exercising these main scenarios.
Finally Framework Design Guidelines introduced me to FxCop which does the great job of encoding the guidelines in a static analysis tool thus catching any accidental slips in our APIs early on. This makes following a large number of the guidelines incredibly easy.
As Miguel de Icaza asserts in the foreword: this book will help you become a better programmer.