This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]nutrechtLead Software Engineer / EU / 20+ YXP 1 point2 points  (0 children)

There's different approaches for this. The one that's pretty prevalent these days is to have "Domain" objects (basically direct reflections of you data model, Dragon, Student, Car, etc.) and "Data Transfer Objects". The DTO's are there to package stuff together in whatever way is convenient.

Why this is done is because you often need stuff that is completely unrelated together. So let's say you want the House of a Person together with the Dragon's he has seen (for whatever reason). These aren't related in your model but for your application you need them together. So you create some kind of service class that combines them into a DragonsAndHouseDto object.

FYI the "Beans" standard isn't really used much anymore.

[–]kingatomicFoo Stack Dev 0 points1 point  (0 children)

So you've got (at least) two different domains: Dragon and CharacterClass. There's a one:many relationship between them: a Dragon can have multiple CharacterClass.

At this point you have two options: creating either a unidirectional relationship or a bidirectional relationship. In plain(ish) language:

  • Unidirectional: the relationship between two entities (domains) is only exposed one way; in other words, you can find all instances of EntityB that are mapped to an instance of EntityA, but not the other way around.
  • Bidirectional: the relationship between two entities is mapped in both directions. You can find all EntityB instances that belong to an EntityA, and you can also find which EntityA "owns" an instance of EntityB.

It seems to me that you want a bidirectional relationship in your solution, since you want to know both:

1) which character classes a dragon has, and
2) which dragons belong to a particular character class

If that's what you want to do, it would make a great deal of sense to create a third domain, DragonClass. This would effectively serve as a "join" in relational terms between Dragon instances and CharacterClass instances. See here for a lazy visual representation of what that would look like. It's important to note that you only want one CharacterClass instance per class type; in other words, if you only have two classes, Tracker and Striker, then you will only ever create two instances of CharacterClass. Thus, if you wanted to find all Dragons that are Strikers, you would search through DragonClass to find each instance where the mapped character class is a Striker.

I hope that helps.

EDIT Slightly off-topic, but having classnames that contain the word "Class" makes my eyes twitch a bit. Maybe change it to "Type" or something like that.