I'm making a code to make a custum TV Dayparting.
So i need to make this schme of data:
- A
dayPartingcan have multiplesDayParts - A
DayPartcan havemultiplesTimeParts. DayPartandDayPartinghave a begin hour and an end hourTimePartit 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
}
I feel i can use the composite pattern, but i have two bad feelings:
- My custom composite pattern is pretty "rigid" because the leafs are always in the lowest level.
- 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