1. Hey Frank,

    isn’t the problem that you introduce high coupling in your classes. Your problem isn’t the null tests, it is that the caller of contract now is tied to the Parties, Client and Address classes.
    I think you should rewrite to:

    if (Contract != null)
    string street = Contract.GetClientStreet();

    and then handle the rest of the code inside the Contract, and Parties classes.
    I always try to avoid calling a member of a member. Something with the ‘law of demeter’ http://en.wikipedia.org/wiki/Law_of_Demeter


  2. Contract.Parties.Client.Adress.Street

    According to most best practices this just isn’t the right way to do it.
    The problem is that the current code knows way too much about the internal structure of the classes. You might consider adding methods to the classes so you could write something like the following instead:



  3. Erno made the point I was afraid that would come up, I believe the pragmatic programmers call it ‘Don’t talk to strangers’. I think this is a good principle that should be honered whenever possible.

    The problem is that in a lot of situations this is just no practical (as is admitted by the same pragmatic programmers). In the project I was taking about the domain model are actually data transfer objects. As they are pure Data transfer objects the do not contain any logic, but are merely generated from an XSD (as is common practice for WCF or ASMX services)

    A common situation where I find myself reaching down a deep dark path into a datastructure is in validating business constraints on input messages. A common practice is to let every validation rule operate on the whole input message, and then let the validation rule it self eveluate whatever data is relevant. This way only the code of the business rule itself knows what exact data it operates on and this knowledge doesn’t get scatterd around.

    One could argue that this is not really OO and I think that is actually true. Service Oriented Architecture and OO are not in all situations best friends.


  4. Partial classes could counter your argument there. As you generate your data transfer objects from xsd’s you could add business logic to them by using partial classes. Then everything Erno said makes sense again. The pragmatic programmers, at least the book, is from the pre partial class area 😉


Comments are closed.