lundi 11 mars 2019

OOP Creational Design Pattern

I have the following data types and I'm struggling to implement a good design to create instances for different types.

Events: I have different type of events (EventA, EventB etc.)

  • Each event might have subtypes. For example, EventAA and EventAB are subtypes of EventA,likewise EventBA and EventBB are subtypes of EventB.
  • Each event has source and output but the types differ. For example EventAA has List<String> as source, EventBB has int as a source. Same thing with the output.

At the end, I need to create EventAA, EventBA with their source and outputs. I tried to apply Abstract Factory design pattern to create events, defined Event, EventSource, EventOutput as abstract class. Also, created EventAFactory and EventBFactory classes. Although, my sub events EventAA and EventAB has source and output, types may differ. Therefore, I couldn't generalize the createEvent() method. For each different type of inputs, I defined a createEvent(type, source, output) method but that doesn't feel right. Use cases for AbstractFactory design pattern online doesn't have subtypes like me (EventAA etc.) and I confused.

Aucun commentaire:

Enregistrer un commentaire