16

I know DTO is a data transfer object and a BO is a business object. But, what does it actually mean? When should I choose one over the other? From, what I understand DTO is just used to transfer data and doesn't have business logic. Does this mean that a DTO doesn't have any method only properties(getter and setter)? But, it still has properties of a BO. Can someone please explain? Thanks.

Sandbox
  • 7,088
  • 10
  • 49
  • 64
  • 9
    @Mitch Wheat: I have already told what I know. I come to stackoverflow not because I can't find answers on the internet. I come here becaused there are experts who really understand the topic well and they answer questions in a simple and lucid manner. Can you PLEASE let me (and others) know why you have asked this question? – Sandbox Jan 09 '11 at 01:16
  • @Sandbox : I asked the question because when I do an internet search for those terms, I get the correct answers. – Mitch Wheat Jan 09 '11 at 01:18
  • 1
    @Mitch Wheat: That is true for most questions on SO or related stack exchange sites. You will find an answer on some blog or a forum. It this the first time on SO that someone has asked a question, which cannot be searched on the internet? – Sandbox Jan 09 '11 at 01:23
  • 1
    I am seeing this on SO, that few members with high rep. increasingly like to humilate and drive away members with low rep. – Sandbox Jan 09 '11 at 01:25
  • @Sandbox : it's true for this question. – Mitch Wheat Jan 09 '11 at 01:25
  • @Sandbox : asking you what you have tried for yourself, is not humiliation. – Mitch Wheat Jan 09 '11 at 01:26
  • @Mitch Wheat: I will leave it to the SO community to decide if what you have said is right or wrong – Sandbox Jan 09 '11 at 01:27
  • @Sandbox : that is very magnanimous of you. – Mitch Wheat Jan 09 '11 at 01:30

2 Answers2

21

DTO is used to transfer data between layers/tiers. For such purpose it doesn't need any methos and sometimes it even should not have any methods - for example when DTO is exposed over web service.

Business object is clever object which contains data and methods which performs operations (change data) on this object. When you expose BO to upper layer, it can call your object's public methods. Sometimes you don't want this and for that reason you create DTO which only offers data but not methods.

DTO doesn't have to transport all BO data. When you follow strict DTO approach you create specific DTOs for each operation exposed on your business layer. For example if your object has audit data like CreatedBy, ModifiedBy, CreatedDate, etc. and you are creating Update method your incomming DTO (with updated object) doesn't need to have these properties because upper layer cannot modify them - only business logic can.

Ladislav Mrnka
  • 349,807
  • 56
  • 643
  • 654
  • So DTOs are ALWAYS used to communicate from BO layer to Data access layer? – Sandbox Jan 09 '11 at 01:20
  • 1
    No DTO is general concept which can be used between any layers. The most common usage of DTOs is between Presentation and Business layer. Another common usage is between tiers (physical boundary). – Ladislav Mrnka Jan 09 '11 at 01:23
  • I see that you understand .net (from your previous answers). So, if I am using MVVM pattern in WPF with a 3 tier architecture, then are my VMs DTO? or will I use VM only for display and use DTO to transfer data from VM to Model and Model to my service? – Sandbox Jan 09 '11 at 01:32
  • I have never used WPF or MVVM so I can't propably answer it. But when you use DTO it has to be defined somewhere and shared between both layers. If VM has some WPF dependency (like special attributes from WPF assemblies or special property implementation for data binding) do you want to have this dependency in your DTOs? – Ladislav Mrnka Jan 09 '11 at 15:11
  • Correct me, if i'm wrong. **Business Object** or **View Object** is for transferring data between **Presentation Layer** and **Business Layer** and **Entity Object** is for transferring data between **Business Layer** and **Data Access Layer**. and **DTO** can be used as a dumb **BO**. – Arash Nov 05 '19 at 17:04
1

Generally, DTO has relative static data for that moment before arrive tier, but BO can dynamically keep state and flow flag value; and BO also could be self contained to have validation or logically reorganization or judgement for some business logic; but DTO 's change depends on tier 's change of data that passed over... But, BO's changes has wider scope, for example , depends on more dynamically update with business flow state, flag 's change, even the identity could be changed in real time , these suppose to be captured and acted to reflect from BO, for example, such as balance from $200 become zero , or balance from $2000 to $5000, then the deal/trade identity or status will change ... this is big difference between DTO and BO .

user3016087
  • 69
  • 1
  • 2