last day (15 days later) » 

7:26 PM
Hi! I would strongly advice to not have the DTO as inner class of the business object. Speaking in clean architecture terms, the DTO belongs to the boundary layer and should thus be separated from business rules and objects
 
Hi! Yes, I agree, it makes sense that DTO and business object should be separated. I more thought about a situation where for instance you have an adapter that receives an object, transforms it to a different form, and then serializes (e.g. to store in a file).
this "different form" can be a private inner class IMO
because nothing outside the adapter needs to know about it, it's an implementation detail to facilitate serialization
 
Mh... with this technique, you hard-couple the business object (partially) to an I/O Channel and thus mix concerns.
Oh wait! You mean you want to make the "serializable form" an inner class of the serializer?
 
yep
assuming that nothing else needs to deserialize it
 
This would imply that you pass the business object to something outside the business layer.
This then gets a question of personal preferences and project conventions. Going strictly by clean architecture, a business object should never be passed to another module.
 
true, but it doesn't necessarily be a business object that you want to adapt and serialize
 
7:37 PM
Well as I said: speaking in strict clean architecture, you have to convert your business object to a DTO always you cross the business boundary.
Reasoning is:
 
yes, that's fine, I fully agree
 
If you use, for example, JPA and you would not do this conversion-step, you would pollute your business object with JPA annotations and thus couple your business object (partially) to an I/O channel.
 
but let's imagine that you have some infrastructure code outside your domain that intercepts your DTOs and for any reason need to adapt them before serializing. In this scenario...
 
In some porjects, this might be okay ("This is a web service with a database and will always be a web service with a database!"), in some projects, you may want to have the flexibility to switch the I/O channels ("Today we do web and database, tomorrow, we do CLI and flat file")
 
but anyway, I think we agree upon the principles
 
7:39 PM
yes we do =)
 
I'm going to delete my comment as it doesn't make much sense without the broader context, as you just proved to me ;)
 
nah, just let it there. It does not hurt
 
all right, let's move on :)
 
maybe someone reads it and starts thinking on her/his own. Then we would have people with own opinions :D
 
thinking for themselves? Blasphemy!
 

last day (15 days later) »