When an object has various formats (XML,CSV) it can be represented in, where should one store knowledge of those formats.
Should the object have knowledge of how it's represented in XML (i.e. letting the object convert itself through some method on the object such as GetXML()
). Is this too much knowledge for the object and should this be stored externally in a repository/service/other layer?
If it is stored in a repository, what happens in the use case where the XML representation of the object must be persisted to a database along with other information, e.g.:-
insert into order values(1, '2004', <order><amount>2</amount><price>19.99</price></order>)
;
...the knowledge of the object's XML structure would be in the XML repository, however the SQL repository would also need this knowledge, and this seems like duplication.
I am unsure as to whether the service layer should be holding object representations either, as it does not seem like this is business logic.
What is the recommended implementation for this use case?