Re: Generics and Polymorphism
Jason Cavett wrote:
On Apr 29, 3:52 pm, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
Alternatively, you can have a less generic Preferences class that has
fields and getters/setters for each preference that can be set.
I'm not sure what you mean by preferences vs. configuration.
(However, intuitively, I would say that these are preferences.)
When you say, "you can have less generic Preferences class..." do you
mean, I don't program to a generic interface and, instead, each
preference object has a similar naming scheme, but each knows exactly
what it has to set and get?
class Preference1 {
void set(String blah) ...
String get() ...
}
class Preference2 {
void set(Boolean blah) ...
Boolean get() ...
}
Something along those lines?
Thanks again for your help.
Actually, I was more along the lines of:
public class Preferences implements Serializable {
private static final long serialVersionUID = 1;
private Color favoriteColor;
private String explitive;
private boolean coldSoup;
public enum Animal {
cat, dog, bird, fish;
}
private Animal pet;
public Color getFavoriteColor() {
return favoriteColor;
}
public void setFavoriteColor(Color favoriteColor) {
this.favoriteColor = favoriteColor;
}
public String getExplitive() {
return explitive;
}
public void setExplitive(String explitive) {
this.explitive = explitive;
}
public boolean isColdSoup() {
return coldSoup;
}
public void setColdSoup(boolean coldSoup) {
this.coldSoup = coldSoup;
}
public Animal getPet() {
return pet;
}
public void setPet(Animal pet) {
this.pet = pet;
}
}
so, if you can use
preferences.setExplitive("Dag-nabbit!");
preferences.setColdSoup(false); // like my soups hot.
preferences.setPet(Preferences.Animal.cat); //
preferences.setFavoriteColor(Color.purple);
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>