Tuesday, 13 August 2013

How to create an Class when its attributes are dynamic & variable in Java, C++ or any Object-Oriented Language?

How to create an Class when its attributes are dynamic & variable in Java,
C++ or any Object-Oriented Language?

Ok, in Object-Oriented Language (OOL), when creating a Class we often know
in advance all its attributes. Ex, Item class should have a fixed
attributes (Color, model, brand, price). So we just:
public Class Item{
private String color;
private String model;
//etc more attribute here
//& set & get method for all attributes
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
}
But what if all the attributes are dynamic? Ex, in 1 company, their item
attributes could be color, brand, but in other company, they don't have
color & brand attributes but have width, height, size...
How to create a Class that accepts dynamic attributes in Java, C++ or in
any OOL?

No comments:

Post a Comment