Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a simple java approach to do it. While designing large systems I always suggest to look at the bigger picture. The issue here is dynamically changing attributes. It would not be easy but yeah it is interesting.</p> <p>The structure of your item class has to be like the following:</p> <pre><code>class Item{ private String itemName; // I assume all items will have a name. private Map&lt;ItemAttibuteName , Object&gt; attributeMap ; // this will be a dynamic map. public Map&lt;ItemAttibuteName, Object&gt; getAttributeMap(){//getter for attribute map if( null == attributeMap) return new HashMap&lt;String, Object&gt;(); return attributeMap ; } // you can synchronize this if needed public void setAttribute(ItemAttibuteName name, Object value){ attributeMap.put(name, value); } public Object getAttribute(ItemAttibuteName name){ return attributeMap.get(name); } } public enum ItemAttibuteName{ SIZE, COLOUR } </code></pre> <p>This approach suites your needs, further you can use a factory pattern to instantiate the Items depending on the category and make it an elegant code.</p> <p>Please get back if you still have some doubts.</p> <p><strong>EDIT:</strong> Now there will be a complicated way to get all the attributes of an element in the code while programming, because you don't have getters or setters for the attributes. Well, the approach will help if you can maintain a Set of attributes added to the Item, in the Item class or you can query for the keySet of the item class's attributeMap property.</p> <pre><code>private Set&lt;ItemAttibuteName&gt; attributes; </code></pre> <p>or</p> <pre><code>attributeMap.keySet(); </code></pre> <p>Happy to Help</p> <p>Dharam</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload