Analysis patterns
Listen to this article
When I first moved over to the cool new world of OO, I just loved the fact that, especially in C++, I could use inheritence to do so many things. I could just create yet another sublcass, override some method/s and bingo problem solved. What I didn't realise was that I was creating an enormouse mess of brittle, crufty, hard to maintain code. Personally, C++ multiple inheritence didn't help! But let's not go there just now shall we :)
So, for a simple problem with some very basic requirements:
- We have bank accounts
- We can transfer money from (debit) at most one account
- We have 2 types of transfers
- Single funds transfers allow crediting to one account
- Multi-funds transfers allow, you guessed it, multiple credit accounts
Now, how would you have modelled this? There are of course no right or wrong answers but I'm curious to hear your thoughts.
You see, the most common solution I come across has two sub-classes, one for each type of transfer. One allowing a single credit and the other allowing a collection of credits.
As you've probably guessed however, this isn't my preferred solution. I'd rather see a single class for a transfer with a collection of credits and some kind of constraint class that holds "rules" regarding minimum and maximum numbers of credit accounts.
I'd say the most influential books I've ever read to do with software developement, in the order I read them, were:
The last is probably not as well known as the first two but, quite aside from the patterns themselves, it fundamentally changed the way I model problems. For one, I stopped creating ridiculously deep class heirarchies to solve every problem I came across.
It's been many years now since I read Analysis Patterns but I've had cause to refer back to it recently in group modelling sessions. If you've not read it I highly recommend that you do.
Comments
I'm recommending "Streamlined Modeling" again. Yeah, I do sound like a broken record (BTW, is there anyone in software development besides me who is old enough to understand that simile?) Streamlined Modeling teaches that at the analysis modeling level, you almost never have class inheritance. That is a design/implementation issue. As far as the analysis is concerned, your domain experts say that you have two different kinds of transfers. If it turns out that the implementations can share some code by inheritance or otherwise, fine, but that's not something that is rooted in the problem domain.
Posted by: Doug | December 10, 2003 11:24 AM
Nothing wrong with sounding like a broken record. I must admit that although it's titled analysis patterns, I really think of them as domain-related implementation patterns hahaha. And don't worry, the book is up the top of my reading list ATM. I'm getting there :-) Cheers, Simon.
Posted by: Simon Harris | December 10, 2003 08:52 PM
Hi Simon,
Here is the way I would have modeled your requirements:
http://www.mycgiserver.com/~nsenthil/articles/SimonHarris.html
Let me know what you think,
Nalla
Posted by: Nalla Senthilnathan | December 14, 2003 09:30 AM
Hey Nalla. Thanks. I'll check it out. -- Cheers, Simon.
Posted by: Simon Harris | December 15, 2003 06:14 AM