I understand that factory pattern is about creation and strategy pattern is about behavior, but I found both pattern seem to be ok in my situation. I am hoping if someone could point out any potential difference in my situation.I need to create a ScheduleService, which consist of several pattern such as hourly, daily, monthly, and irregular. One way to do this is strategy pattern where I create a interface and implement it with classes for each pattern.I think I also can use factory pattern along with enum for each pattern. The factory pattern could takes in this enum and construct the schedule object with different member variable. Basically I could use the same method with different member variable to do the computation.Please comment on these two designs, I would like to have some feedback.
Factory Pattern or Strategy Pattern, what to use under this situation, please comment
design;design patterns;object oriented design
Well, as you've said, the Strategy pattern is a behavioral pattern. It's a way of defining an abstraction of an operation, so that you can define several different implementations. Something still has to select and create a concrete implementation at some point. Maybe a Factory will do? In your second scenario, you describe a Factory which picks an implementation based on a parameter, and puts it in a schedule object; since it can be any one of several concrete implementations, that schedule object presumably expects a base type all of them derive from (like an interface). Looks a lot like the Strategy pattern. My point is, these two patterns serve two different purposes - and nothing prevents you from using both here. (But, of course, never use a pattern just for the sake of using a pattern - try to understand what's the idea behind it, and then see if it fits with what you are trying to do.)