Wrong. Very wrong. Experience has fully vindicated Steve's assertion that the interesting stuff really does lie in the relationships, not the objects. In fact, the key to understanding any domain always comes down to formalising the relationships among the domain concepts. So I'm constantly frustrated by models in which relationships are second class citizens, demoted to pointers between objects with perhaps a role name. Something like this:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDLpLCJQ6ABDUJmjFI-ZGES1x1RcyPYbFSr4k0-4v0T7vgcmhyRouyvwfTtxFhufLsXadjKPbsmjRduMF9OX-xvXb1AnrndPRNipjhRxmmZFowNZKKmVNidRRCqAdfKJeGnJgO5PtHU8HZ/s320/pointer-based+naming.jpg)
Steve (and my colleague, close friend and boss at the time Alistair Blair) instilled in me the importance of naming relationships using verb phrases. I've found it extremely valuable, more recently adopting the style recommended in Simsion and Witt's excellent book on Data Modelling. So the model above becomes:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRYDSX6D8EKPGbBSEdk2UfGqrmqkgMkw5iUHcd907wKSD_kABDki54joLNuYtJ-ts9Lhuo8cdWR93ZZLdvT9SxJ-Jj7tCGN83akjHZfrJWGaVIrQV7PGxryRjQe98z9YAVAcJD_yE4r-Ti/s320/Verb+Phrase+based+naming.jpg)
The model also makes assertions about the relationship. An Account must be owned by exactly one Customer. Is that right? What about joint Accounts? Again, the model prompts the question. And so on. We can also generate textual facts (or "business rules") directly and algorithmically from the model, according to the technique described by Simsion and Witt. So we'd get:
Each Person may own one or more Accounts
Each Account must be owned by just one Customer
Furthermore, it tells us something about the behaviour, or interaction between Customer and Account. On first glance it's pretty simple: create a new account, assign it to the owner. Job done. But what happens if the Customer goes away? In typical OO programming terms, that responsibility would lie with the customer:
foreach a in self.accounts:
a.delete()
But why should it belong with the Customer? The required behaviour arises because of the Relationship: it's not intrinsic to the Customer. Another case in point is transfer of ownership. Where does that belong? The Customer? The Account? No. It belongs in the relationship.
So the fun does really happen in the Relationships - thanks Steve and Alistair for enlightening me.
No comments:
Post a Comment