ACCU London - June 2012

Ed Sykes – Proper OO

 

Ed Sykes is probably like many of us; he’s been “doing” OO for many years. But at the same time we find ourselves continually questioning what the 3 pillars of OO (encapsulation, polymorphism and specialisation) really mean. Yes you’ve been adhering to them but can you quantify how “OO” a design is? Ed’s clearly been musing this and one of the pillars – encapsulation – in particular, as any accu-general followers will no doubt know. So he wanted to share what he’d discovered with a larger audience. The venue was once again the offices of 7 City and around 20 people (a mixture of regular and fresh faces) showed up to find out what he had to say.

 

Although Ed stood at a lectern, this wasn’t a parapet. This was more a workshop where he stood at the front and gave a brief overview of himself and what he understood by the term encapsulation and then started to open it up to the audience to see what their opinions were. The initial example was a simple Player class that had two properties – Score and Name – that were first exposed as public fields, and then as (C#) properties. The question then was whether the latter was considered more encapsulated than the first, and if so why?

 

It’s amazing how much discussion such a simple question can generate and after a brief detour about what the modern texts are on OO design & programming are(still Meyer and Booch it seems), Ed moved the question on by providing some additional context. He also switched from background slides to an IDE so that we could explore the problem together which now included a Leaderboard class which is used to display the Player’s scores in some way.

 

This is where the high-bandwidth communication that a session like this provides really starts to pay dividends. Although Ed has some idea of how he wanted to transform the un-encapsulated Player class and use the number of compiler errors as a very loose indicator on the amount of encapsulation, the audience had other ideas about the way the design could be improved. In particular the discussion started to ramp up once the question moved to how an update to a player’s score might be handled. Ed’s initial suggestion was to follow the principle of Tell, Don’t Ask which improved encapsulation, but at what appeared to be an increase in coupling.

 

Even a simple problem such as this raises so many questions that it’s hard to come to any sort of consensus – the lack of constraints and concrete requirements just means that so many choices are potentially valid. But at the same time the freedom allowed the audience to question the very role that the Player class was providing and whether it even needed a public presence at all which was not a direction I think Ed ever expected to be exploring.

 

Ultimately we were out of time and so needed to adjourn to the pub across the road to contemplate how things turned out. There was no doubt that the people I spoke to found the whole experience very enjoyable and it just goes to show that even though OO has been the dominant force for a considerable number of years we still have so much to learn.

 

Chris Oldwood

15 June 20128

 

Bio

Chris started out as a bedroom coder in the 80s, writing assembler on 8-bit micros. These days it’s C++ and C# on Windows in big plush corporate offices. He is also the commentator for the Godmanchester Gala Day Duck Race and can be contacted via gort@cix.co.uk.