Advantages of Domain object representing only elements of one type over being able to represent several different types of elements RRS feed

  • Question

  • User1306679194 posted



    1) As far as I’m aware, each domain object instance ( at BLL layer ) should completely represent an element of the domain ( an employee, book, car etc ).


    So what is an advantage of having two types of domain objects, say one type representing a particular forum and other type representing a thread(s) in that forum, over having a single domain object type representing both a forum and thread(s) inside this forum?

    Another example: what’s an advantage of having two types of domain objects, one representing an instance of a car, and other representing an instance of a bus, instead of having a single type of a domain object representing both a car and a bus?

    thank you

    Saturday, December 19, 2009 11:52 AM


  • User559104930 posted

    There are entire books written about this very subject so answering it in a paragraph or two is going to be tough, but here goes...

    Objects are about behavior. The behavior and data that supports that behavior (properties) of, as in your first example, a forum are quite different from the behavior and properties of a thread in that forum. The behavior and properties of a message in that thread is different from the thread itself. The objects each have a different set of concerns, just as each object within a layer has a definite set of concerns. By keeping a definite separation or boundary of those concerns, we create code that is more testable, flexible, maintainable, and enduring.

    As for your second example, a bus and a car do have similar or shared behaviors and properties (wheels, doors, steering wheel, transmission, etc.), but you would not use the same transmission in a or engine in a car as you would in a bus. 

    I recommend that you spend some time looking at the SOLID design principles to get a better idea of how they play a role is this as well:


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 19, 2009 1:25 PM