mardi 17 novembre 2020

Is it Ok to inherit from an empty class?

I have an entity which has info1 or info2 dependently from its type, but only one of these infos should be filled. These infos have absolutely different properties. So my entity looks like this:

public class SomeEntity {

  private SomeEntityType type;

  private Info1 info1;  

  private Info2 info2;  

}

So my question is this Ok to create some empty abstract class Info and inherit Info1 and Info2 from it? (Since I think that the number of such Info classes can grow and I will need add all such infos to SomeEntity)


public class Info1 extends Info {
  /* some properties */ 
}

public class Info2 extends Info {
  /* some properties */ 
}

public class SomeEntity {

  private SomeEntityType type;

  private Info info;   

}

Aucun commentaire:

Enregistrer un commentaire