oop - Should DTOs in a composite DTO reference each other by primary key or by object reference? -


there recommendation transfer objects should not contain object references other transfer objects. instead, should use primary keys of other transfer objects foreign key fields.

simple example order , customer entities

clearly, orderlistdto containing list of orders without customer details contain foreign keys details of ordering customers.

a composite dto orderwithcustomerdto have object references orderdto , customerdto. should embedded orderdto have object reference customerdto in case? or should use primary key of ordering customer?

indication object references

one advantage client can directly use transfer object, e.g. presentation model. tend accept approach transfer objects self-contained, e.g. composite dto related dtos or complete tree. client can rely on self-containment. client doesn’t need post-process transfer object @ all.

indication of primary keys foreign keys

the advantage internal , external references treated same way. tend require approach transfer objects might contain external references, e.g. subtree external childids. client must iterate on complete list resolve external childids.

more complex example tree or subtree

the transfer object in question tree or subtree. technically, it's list of nodes.

is ok if nodes in transfer object reference each other object references nodetowithobjectreferences below?

public class nodetowithobjectreferences implements serializable {     private long id;     private nodetowithobjectreferences parent;     private list<nodetowithobjectreferences> children; } 

or must transfer object replace every object reference foreign key field nodestowithforeignkeys below?

public class nodestowithforeignkeys implements serializable {     private list<nodedetail> children; }  public class nodedetail implements serializable {     private long id;     private long parentid;     private list<long> childids; } 


(i opted transfer objects encapsulate domain model clients , provide client specific data views.)

as general recommendation, transfer objects should not contain object references other objects. instead, should use primary keys of other objects foreign key fields.

could attach link source of recommendation? it's @ least not obvious me.

in current project use transfer objects contain object references. it's convenient , haven't met problems approach yet.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -