This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: Domain Objects as dumb data holders
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
In the last days i read several times (in books and in the web) that implementing Domain Objects as simple data holders is not OOP and is in general bad practice. I must admit that i do the same thing. Lets see what i do regulary (and i am sure that many if not most others do the same):
public class User() {
private String name;
private Date birthday;
public String getName() {
return firstname:
}
public String getBirthday() {
return birthday;
}
public void setname(String n) {
name = n;
}
public void setBirthday(Date d) {
birthday = d;
}
}
As you can see, this is a pretty normal Domain object that will be persisted into a database. As we live in a transparent persistence world, we dont need anything more. But some people say that this is not OOP, because we dont have any behavior, just a state.
First of all, i cant see too much other methods i should implement here. I think those people want methods like:
public int calculateAge() {
// calculate age
}
So basically i can see some more methods one could implement, but excessive business method coding is IMO not apropriate.