Women in Technology

Hear us Roar



Article:
  Wiring Your Web Application with Open Source Java
Subject:   Not a good template for building a domain layer
Date:   2004-04-13 08:02:07
From:   Groo
Nice job putting this article together, however this is a good example of what Martin Fowler recently described as an Anemic Domain Model:


http://www.martinfowler.com/bliki/AnemicDomainModel.html


By putting your business logic in your service layer, as opposed to your domain layer, you miss out on all the important benefits of OO for your business layer, and end up back in the procedural world.


Main Topics Oldest First

Showing messages 1 through 2 of 2.

  • Not a good template for building a domain layer
    2004-04-18 05:43:01  wrschneider99 [View]

    Being in the procedural world is not necessarily a bad thing. The request-response aspect of web programming often lends itself more naturally to procedural than OOP methodology--otherwise, PHP, Python and Perl wouldn't be so successful.

    There are some practical obstacles to getting more benefits of OO (encapsulation in particular) inside domain objects. One is that Hibernate and other persistence layers force you to have setters for all properties and directly expose (untyped) collection instances. That makes enforcing any real invariants on the domain objects nearly impossible--for example a setter can't throw an exception if some business rule would be violated, because the rule depends on other properties that might not be loaded from the DB yet.

    Once I attempted to solve this problem by making richer domain objects that wrapped the "dumb" persistent state beans. But this breaks down when you have transactions that span multiple objects/tables (as most do!)

    There is a place for OOP in web applications but for transient domain/data objects constructed and thrown away in the scope of each request, the costs to get the benefits of OOP may outweigh the benefits.
  • Not a good template for building a domain layer
    2004-04-13 12:15:45  while(true) [View]


    By putting your business logic in your service layer, as opposed to your domain layer, you miss out on all the important benefits of OO for your business layer, and end up back in the procedural world.



    "all the important benefits of OO" We are missing all of them. I'm not really seeing this. I read Martin's article and I'm still not really seeing what benefits I'm missing by having a service layer.

    Martin's article didn't give enough concrete examples to convince me that a service layer is a bad thing.

    Anyway great article! My 2 cents!