object inheritance

object inheritance

Old forum URL: forums.lhotka.net/forums/t/3406.aspx


jhw posted on Tuesday, August 21, 2007

Rocky states in his book, in chapter on designing his objects: 'A common mistake is creating object inheritance based on data rather than behavior.'

 

What do people generally think when it comes to the busniess rules associated with data. I have been creating inheritance based on data, so I don't have to recreate the business rules, which are usually quite simple(string required, max value). Is there some point where people draw the line such as data based inheritance for complex business rules for a property, or is it better just to avoid this, and use cut and paste to recreate them?

triplea replied on Tuesday, August 21, 2007

Well (as usual) that depends on the case. If for example we have a DB table called Person which contains data for BOs Customer, Employee, Manager etc etc, then I would stick with Rocky's recommendation since their behaviour is completly different.
But in instances where that table would contain data for BOs Customer, VipCustomer etc that actually share some behaviour (e.g. some business methods, authorization etc) then I would (and have) used inheritance.
But if you are purely conserned about the fields and their associated simple rules (which is a valid conern) then don't sacrifice your object model in order to avoid cutting and pasting. In the end of the day there is CodeSmith and MyGeneration that can easily create just these for you.

Copyright (c) Marimer LLC