Object Discovery

During this session we performed a modified version of a CRC. One thing I always find with CRC sessions is how useful they are. The problem I and others find is when it comes to day to day development, I'm too eager to start coding without performing some sort of up front design.

Events

In order to write flexible OO code, you need to hide as much state as possible. While this is great in practice it turns out to be very difficult to achieve in the real world. One method of getting around this is to make use of events aka the observer pattern.

Kevin used a wiki as an example. Consider a page that is updated. If this page was to fire a changed event, then anything that is listening for these events would be notified. They observers could then react once the event was received. The nice thing about this approach is that the code obeys the open/closed principle. New features can be added without the need for the change to have a large, rippling effect.

Nouns and Namespaces

When I was first exposed to object oriented programming, apart from believing that inheritance was the coolest aspect of OO, I was also led to believe that using nouns when designing classes can be useful. It turned out that this was a fallacy. If you follow this advice you'll end up with a small collection of classes that do everything. The biggest revelation I had during the session came from the importance of namespaces. Using nouns for up front design can be extremely useful if you remember that the noun can potentially be a namespace. This means you'll end up with a handful of namespaces that are relevant to the domain in question. Inside these namespaces you will have one or more classes that do one thing, and one thing well.

Closing

At the end of the session I was left with many questions and new ideas to test and try out. Using events to hide state, yet allow other objects to interact when required was a real eye opener. However it turns out that when actually trying to implement these ideas in code, it is actually quite difficult due to my current thinking. The plan for the next month will be to explore these ideas in more detail and see what affect it has on my day to day development.


Tech

By: Codeweavers - 03/12/13

More stories by Codeweavers

Our cookies

We use analytics cookies to collect information about how our site is being used. We use these cookies to allow us to improve our services.