oop - Object modeling: replaceable object type and changing structure -


what best way model class, structure able change based on type? in general scenario, implement using inheritance, have situation, when must possible change type afterwards.

i have 2 ideas:

1) using inheritance anyway , when type change, delete existing object , create new one, based on properties, have.

2) using composition reference 1 of types (each type contains unique properties).

public class theobject {   private type type;    // more properties , methods.         }  public class type1 extends type {   // on properties }  public class type2 extends type {   // different properties... }  ... , that's continue... 

for reason second 1 feels odd way approach problem, because think type telling type , actual data should somewhere else, not inside instance of type. maybe wrong that.

it'd nice hear opinions , ways solve problem.

thank you.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -