Latest Posts - page 17
-
Iteration and Nested Blocks
I recently ran into an interesting design challenge involving the Resource Acquisition Is Initialization (RAII) idiom and the Composite design pattern.
-
Musings on a New C++ Project
For the past few weeks, I’ve been spending most of my time writing a new application in C++. Normally, my C++ work is on applications that have been around for a while, so doing something greenfield has been a refreshing change. Almost all of my C++ work these days is on Linux, but this new application initially needs to run on Windows. We want to move it to Linux eventually, and we like to do most of our development in Linux, so we decided to make the application cross-platform right away.
-
Playing the Inheritance Card
Object-oriented languages typically support some form of inheritance.
-
Liskov Substitution Principle
No discussion of inheritance would be complete without mentioning the Liskov Substitution Principle (LSP), the “L” in the SOLID acronym. Barbara Liskov introduced a “substitution property” in 1988. There’s a more formal definition, but essentially it means that if you have some code that works with some type
T
and you instead give it something of typeS
, then if the code continues to work correctlyS
is substitutable forT
. -
UnitTest++
There have been many C/C++ unit testing tools over the years, from CppUnit and CppTestKit (which seems to have disappeared from the web) to Google Test and CppUTest. I’ve tried many of these, but not all of them.
-
Template Method and Inheritance
In Design Patterns, the Gang of Four describe the Template Method pattern. In this pattern, a base class method describes the structure of an algorithm or process and calls other methods for the steps. The base class can either force subclasses to implement the step methods or it can contain a default implementation that subclasses can choose to override if necessary.
-
ComposedMethod and Inheritance
In Smalltalk Best Practice Patterns, Kent Beck describes a pattern called ComposedMethod. The basic idea is that a program should be divided into methods that each perform one identifiable task. Each method should be written so that its operations are all at the same level of abstraction. This is a very good pattern, and well worth using.
-
Speaking at GoGaRuCo 2014
I’m thrilled to announce that I’ll be speaking at the Golden Gate Ruby Conference 2014 (GoGaRuCo), September 19-20 in San Francisco. I’ll be presenting “Gilding the Rose: Refactoring Legacy Code”, where I’ll show how to use tiny refactoring steps to tame legacy code.
-
Base Class Hubs
When designing base classes, there are a number of guidelines and patterns that can impact the design. One of those is the idea of “hubs”. Thanks to my wife for the inspiration on the name.
-
One Assertion Per Test
A common piece of advice in the test-driven development (TDD) community is to limit yourself to one assertion per test (OAPT). Others disagree, finding the guideline too restrictive and dogmatic. Still others propose a compromise: you can have more than one assertion in a test, but they must all be checking related aspects of the same outcome.