vendredi 3 juin 2016

Is a good idea use composite pattern for this?

I'm making a code to make a custum TV Dayparting.

So i need to make this schme of data:

  • A dayParting can have multiples DayParts
  • A DayPart can havemultiples TimeParts.
  • DayPart and DayParting have a begin hour and an end hour
  • TimePart it is only an hour and have the program to be shown at that time.

At the first time i just use Lists to do the Job, but i started to think that was too "not open to extension" and too "to implementation and not to intarface" solution, so i started to search an alternative solution to this problem.

I was thinking in use the composite pattern, the pattern provides flexibility, open the expansion and allows me to work with composite and individual objects uniformly.

So, i think my classes should be:

class AbstractDayparting{ //
}
class DayParting extends AbstractDayparting{ //Composite
}
class TimePart extends AbstractDayparting{ // Leaf
}

enter image description here

I feel i can use the composite pattern, but i have two bad feelings:

  1. My custom composite pattern is pretty "rigid" because the leafs are always in the lowest level.
  2. I need to get objects from a particular level.

I don't know if (1) is fine, and (2) i don't know how to get all the the composite objects of an specific type (for ex: All the DayParts).

I'm forcing the pattern? it's there a better solution to this problem?

Aucun commentaire:

Enregistrer un commentaire