What is a DTO and BO? What is the difference?
Asked Answered
I

2

25

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.

Ishmaelite answered 9/1, 2011 at 1:4 Comment(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?Ishmaelite
@Ishmaelite : I asked the question because when I do an internet search for those terms, I get the correct answers.Lackadaisical
@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?Ishmaelite
I am seeing this on SO, that few members with high rep. increasingly like to humilate and drive away members with low rep.Ishmaelite
@Ishmaelite : it's true for this question.Lackadaisical
@Ishmaelite : asking you what you have tried for yourself, is not humiliation.Lackadaisical
@Mitch Wheat: I will leave it to the SO community to decide if what you have said is right or wrongIshmaelite
@Ishmaelite : that is very magnanimous of you.Lackadaisical
I agree with @Sandbox, if this is not a duplicate developer question in SO, then we should try to answer it or ignore if you do not know the answer to it or ask for further details that you need. Please do not discourage or redirect them to search online. I do not think this question needs any more information/research attached.Diminished
M
32

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.

Mccusker answered 9/1, 2011 at 1:12 Comment(5)
So DTOs are ALWAYS used to communicate from BO layer to Data access layer?Ishmaelite
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).Mccusker
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?Ishmaelite
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?Mccusker
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.Penology
S
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 .

Shallow answered 30/12, 2014 at 19:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.