I have the following code:
public class Toy {
static protected int d = 1;;
protected int id;
protected double price;
protected int minAge;
protected int maxAge;
protected String size;
protected String name;
public Toy(double price, int minAge, int maxAge, String size) {
this.id = d++;
this.price = price;
this.maxAge = maxAge;
this.minAge = minAge;
this.size = size;
String s = this.getClass().getName();
this.name = size + "_" + s.substring(s.lastIndexOf('.') + 1) + "_" + id;
}
public double getPrice() {
return price;
}
public int getId() {
return id;
}
public String getSize() {
return size;
}
public int getMinAge() {
return minAge;
}
public int getMaxAge() {
return maxAge;
}
public String getName() {
return name;
}
public boolean check(double price, int minAge, int maxAge, String size) {
if (this.price <= price && this.minAge <= minAge
&& this.maxAge >= maxAge && size.equals(this.size))
return true;
return false;
}
public String ToString() {
return name + "_" + minAge + "-" + maxAge;
}
}
and some subclasses, one of them:
public class Ball extends Toy {
public Ball(double price, int minAge, int maxAge, String size) {
super(price, minAge, maxAge, size);
}
}
I think, that this is no good way to create class, which does not have new fields/methods/.
Can you give me an advice if i am right? "What are the criteria for creating a new class? Should there be a new class for any different instance? Is it good to create a sub-class if it would not have any new fields/methods?"