Archive for July, 2006
While a big fan of patterns I found the original Gang of Four (GoF) book a little dry and so had left the pattern books alone until Martin Fowler’s Patterns of Enterprise Application Architecture (PEAA), got referenced so many times on-line I gave in and purchased a copy. I’m glad I did – even if the examples are mostly in Java with the very occasional one in C#.
The patterns in the original GoF were really about the interactions between the objects themselves and whilst PEAA has some object-to-object interactions it concentrates on problems encountered in “Enterprise Applications”. This includes database mappings, transactions, web pages and concurrency.
The first half of the book provides a readable narrative and discussion of the various patterns with recommendations for when to use each and when to avoid. Part two explains each pattern in detail providing an essential reference to the patterns themselves. This mix of half-narrative and half-reference works very well and is certainly something other programming books would do well to steal.
As somebody who has been writing ‘Enterprise’ applications for some time it is interesting to see many of the problems described in neutral terms as well as the road-not-travelled alternatives and a rationale for their existence. Even if you came up with something similar yourself (and I’m sure you’ll find a few) giving it a meaningful common name makes life easier when discussing the solution with others.
A fair chunk of the book covers object-relational mapping (ORM) and it addresses most all the issues including whether to go full domain model/data mapper, active record, record set as well as the more intricate issues such as lazy loading, locking, identity map and approaches for how many tables to use for a given object.
There are a couple of issues I have with some of the patterns that don’t seem to be addressed so I’ll throw them out here:
The identify map’s description is “Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them.” There are two problems here;
- Objects become stale as other users perform updates that your browser/user can never see until your session terminates and thus looses your map. “Log out to see changes” is not acceptable.
- Resource consumption is heavy as your identity map effectively holds every object loaded in memory regardless of whether it’s used any more. Those objects may reference other objects too – combine this with a web server and you’re looking at a recipe for disaster as resources dry up.
One approach would be use develop your map using some form of weak reference mechanism. This would mean that once your code looses the last reference the object will be eligible for garbage collection and subsequent reloading from the database. This effectively kills off the secondary role as a cache but better than a web site running out of memory showing lots of old data.
Martin puts forward his discussion of the Money class and while the rounding is useful in my experience a monetary amount and a currency isn’t much use without some way of getting an exchange rate to the base currency.
The samples Martin provides here are not thread safe and you could easily find yourself with two different objects where you expect one. For a section on lazy loading for enterprise apps not having a double-check lock is a bit sloppy. To correct the sample on page 203 would be (I’ve also converted it to C# 2.0);
public List<Products> GetProducts()
if (products == null)
if (products == null)
products = Product.FindForSupplier(GetID());
Overall a very good book – I really need to get to grips with the patterns Foreign Key Mapping and Class Table Inheritance now ;-)
I was very fortunate to receive a Nintendo DS Lite for my birthday and a voucher for a couple of games – I’d wanted one for a while but put it off being that I already a couple of hand-held gaming systems.
The DS Lite is tricky to compare to the PSP being that they take such different approaches. Sony has tried to make the PSP a portable multimedia station supporting UMD movies, video and music on memory sticks and it’s reasonably large wide-screen display as well as playing games.
As the saying goes “jack of all trades, master of none” sums up the PSP quite well. The UMD movies have been a bit of a flop – who wants to pay another £15 for a movie they already own to watch it on a smaller screen? Anyone wanting movies on the go would be better off with a portable DVD player or laptop.
Likewise it’s too big to be used as a portable MP3 player and the interface is years behind the likes of the iPod not to mention the fact there is no on-line music store to grab the tracks from anyway.
The PSP has impressive specifications for the games but basically it’s a PS2 in portable format with WiFi ability. Sure this is all well and good but with costs of games spiralling out of control the development houses want to stick to the same-old-formula of franchise titles and dull tie-ins something needs to be done. Sony cutting off PSP home-brew exploits with every release isn’t helping.
Which is what Nintendo are doing with the DS Lite. I brought a handful of the games which come on tiny cards resembling SD memory cards and while some of them are rather formulaic of the past – Sonic Rush for one – others take some innovative approaches.
Another Code is one such title and although the well-written story is a little too short and linear it features lovely artwork and includes those innovative controls methods I mentioned. Dragging, tapping, twisting and stroking the pen across the screen are the normal course while blowing into the microphone and shutting the lid all form part of the interface. It seems unfortunate that it only has two save game slots – I thought three was the course.
Brain Age is a far less ambitious title when it comes to control but one that is fun nevertheless and the way it continues to update and unlock elements each day as you progress through the tests and assessments keeps you coming back for more. The Soduku puzzles are also fun and can further unlock training and testing elements as well as hints and tips. The graphics and sound could have done with a bit more work however the ability to have four profiles and compare results between yourself and your friends/family keeps the competitive edge going.
Nintendogs…. well everyone raved over it but personally I really can’t get into it. There are dogs. You can teach them tricks… they remember their name. Okay, it has pretty graphics and cutesy appeal but it’s really not for me.
WarioWare: Touched! was one of the titles I got to try out when Steve brought his DS round a couple of months ago and the brief tapping fury needed a revisit. It’s good fun for a pick up and go but the lack of multiple profiles means the whole challenge element is a big missed opportunity. I guess you need two DSs for that…
Animal Crossing is currently at the top of the various game charts. I’ve spent an hour or so with it and again haven’t found myself particularly gripped – much like Nintendogs.
Sonic Rush I brought of curiosity and while the graphics and sound are up to their part it doesn’t really seem much different from the Sonic games I played on my sisters GameGear so many many years ago apart from the face it spans two screens and the batteries last longer than an hour.
The hardware itself seems well built, solid and glossy reminding me of the iPod and the screens are bright and solid to the touch (well, the lower one is). Apparently the DS Lite supports some kind of WiFi network although I’ve not been able to get that to do anything just yet. Perhaps it’s because the WiFi here is encrypted – I guess I should RTFM…
While .NET has a URI class it’s not great. They don’t expose the various parts as properties and you can’t manipulate them either. Many projects I’ve seen (Subtext included) just try and manipulate them via strings which varying degrees of success.
Here’s a C# .NET URL decoder that uses a regular expression I developed for performance based on a VBScript class I developed a while back. Comments and white space have been removed to keep it short.
There were some odd bugs in this class. It is currently being revised and unit tests written. It should turn up later this month (June 2011)