Re: Quick inheritence question
On Jan 4, 10:46 am, andymconl...@googlemail.com wrote:
Hello all,
Would the following be considered bad practice...
I have a very simple bean called "SimpleTypeBean" which is constructed
as follows:
public class SimpleTypeBean {
private long id;
private String description;
public SimpleTypeBean() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
I then need to declare a very similar bean (in fact, it is identical
in terms of data types), except one of the identifiers is called lob
not id, so I have done the following:
public class LobBean extends SimpleTypeBean {
public LobBean() {
}
public long getLob() {
return super.getId();
}
public void setLob(long lob) {
super.setId(lob);
}
}
Is this considered bad practice or is this what I should be doing?
Many Thanks
Andy
Two things going on here. First, the simple thing...
I think the important part here is, "One of the components is called
lob ***NOT*** id."
So, you're saying, LobBean extends SimpleTypeBean. So, because of
that, your LobBean has TWO long values (lob and id). I don't think
that's what you're really looking for. So, the simple solution is
that LobBean does not extend SimpleTypeBean.
Slightly more complicated, but makes more sense...
BUT, as you have noticed, both beans do share a description. And, if
you also noticed, "lob" and "id" are *exactly* the same thing...they
are both long values. So, the only difference is what you name them.
In my opinion, that's not a difference. Really, you could use Simple
as an LOB and be perfectly fine. (Of course, if LobBean has OTHER
differences, you would want to extend SimpleBean and then add the
additional features.) The point I'm trying to make is that id = lob
for your purposes. Don't make it more difficult than it is through
your variable names (which nobody is going to see anyway).