Wednesday, November 10, 2004

In the 'for what it's worth' category

I've been going over some older code I've written (more than 2 years old) and comparing it with more recent code. In a purely subjective judgement I think much of my recent code is much more OO than previous code.

For example, say I'm writing a class that performs some lengthy operation in a separate thread where there's a need to periodically inform the containing application of progress. The way I used to do it was to add a window handle, and a custom message code to the class and post messages as necessary. In other words, I'd build into the object the assumption of a specific notification method with no easy way to change the behaviour.

These days I do the same thing by calling a virtual function passing the notification message and expect the user of the class to write a derived class that does application specific things with the notification message. Simple and obvious huh? With my 20/20 hindsight yes, but it's taken a while to get there. and I attribute the change to my writing articles for CodeProject. The fact is that when you know your article is going to be picked apart by a ravenous mob of bloodthirsty nit-pickers it concentrates the mind wonderfully!

No comments: