开发者

Difference between Data transfer Object (DTO) & a dumb business object?

I am using dumb business objects in my application. Ju开发者_JAVA百科st used a DTO to transfer selected properties of object but I am wondering what is the difference between the two ? I cant find any.


When you say "dumb" business objects, you're effectively making those objects the same thing as a DTO. What makes a business object a business object is the addition of validation and other functional logic. I disagree with user 'no' when he says that business objects require setter and getter methods; they can use properties just fine, they just need a lot more than either one.

A common perspective is that business objects should be allowed to hold invalid values, and only throw exceptions when attempting to persist to the database, in which case properties work perfectly well. Most applications, however, want a way to provide feedback to the user before attempting to post to the database.

Rockford Lhotka's CSLA.NET approach is to use an IsValid() method on the business object, with a set of rules that have been assigned to the object itself. There are other ways to address this, but the key is that a business object performs validation. "Dumb" business objects really are just DTOs, as you suspect.


Maybe a little redundant, but I already typed it so hey ;)

To oversimplify (a lot), the business objects should have getter / setter methods, and the DTO should just have properties. The business objects need to obey you business rules, but the DTOs are just for transferring data; they don't need to obey any rules and should be designed to get data in and out of them as quickly as possible.

In a weakly-typed language like PHP DTOs are not always necessary as arbitrary properties can be given to generic objects on the fly. They can still be useful for documentation, though, and strongly-typed function parameters.


I would say that the only difference is that of intent, assuming your dumb business objects only hold state and no behavior.

In that context:

  • DTOs are intended to transfer data between application layers
  • Dumb Business Objects are part of your domain model
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜