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


ok, in object-oriented language (ool), when creating class know in advance attributes. ex, item class should have fixed attributes (color, model, brand, price). just:

   public class item{      private string color;      private string model;      //etc more attribute here       //& set & method 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 if attributes dynamic? ex, in 1 company, item attributes color, brand, in other company, don't have color & brand attributes have width, height, size...

how create class accepts dynamic attributes in java, c++ or in ool?

how create class accepts dynamic attributes in java, c++ or in ool?

it depends on how want use this. in many cases, rework class contain type of dynamically growing collection, such std::map in c++ or map (or dictionary) in java.

this allows create , add arbitrary data per instance key chosen @ runtime.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -