vendredi 9 juin 2017

When should inheritance(Parent <-- Child) be used and when Object with Enum "Type / ObjectType" to differentiate

like the title above I have the following Scenario.

Scenario 1: Base class Event with an enum to differ between the different EventTypes. It also holds all additional Properties that are needed by the EventTypes.

Or Scenario 2: Base class Event without an enum. Different ChildEvent classes that Inherit from the base Event class. So the additional Properties that are needed for the ChildEvents are defined in the child class.

advantages Scenario 1:

  • simple storing of the Event for example in an Dictionary
  • using simple if statement like if(event.type = Event.ChildEvent) to differ
  • good to use in a factory ( set type based on given Properties)
  • good to use with json?
  • ??

advantages Scenario 2:

  • more Type save
  • good to use with factory
  • ??

disadvantages Scenario 1:

  • possible to call null values
  • a lot of properties
  • ??

disadvantages Scenario 2:

  • not possible to save all EventTypes in one Dictionary
  • more code to write?
  • ??

I use C# client and java on the backend side.

Aucun commentaire:

Enregistrer un commentaire