-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to implement a java aggregate (as Eric Evans defines it)
PostPosted: Mon Jul 14, 2008 10:38 am 
Newbie

Joined: Fri Mar 14, 2008 4:20 am
Posts: 17
Hello!

If you have a Java aggregate (as Eric Evans defines it) which contains a one to many relationship where every child object belongs to a certain aggregateRoot. How do you implement this in a way that the code expresses this relationship?

I came up with the following idea:

Code:
class aggregateRoot {
private List<Child> children = new ArrayList<Child>();

//Noone is allowed to modify the collection without the root knowing.
public List<Child> getChildren() {
  return Collections.unmodifiableList(children);
}

public void removeChild(Child child) {
  children.remove(child);
}

// New Childs can only be added to one aggregateRoot.
// There is no way to add a Child to more than one root.
public Child addNewChild() {
  Child newChild = new Child();
   children.add(newChild);
  return newChild;
}

}

class Child {

// Properties....

// Child cannot live on its own, so only aggregateRoot can create a Child.
protected Child() {};

}




kind regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.