Strategy Pattern for Multiple Type Codes
From: Clint Shank (clintshank_at_hotmail.com)
Date: 02/10/05
- Previous message: alAzif: "Re: Is it better to pass objects or discrete properties to methods?"
- Next in thread: kurbylogic_at_hotmail.com: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: kurbylogic_at_hotmail.com: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: H. S. Lahman: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: topmind: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: Daniel T.: "Re: Strategy Pattern for Multiple Type Codes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 10 Feb 2005 12:21:41 -0800
Please bear with the contrived example... Suppose we have an Employee
class whose functionality depends on several type codes,
manager/engineer and hourly/salary. Now, any Employee can be any
combination (manager/hourly, manager/salary, engineer/hourly,
engineer/salary). Some of the behavior depends on just the
manager/engineer type code. Some of the behavior depends on the
hourly/salary type code. And some of the behavior depends on all four
cases. Specifically,
Case 1: Just engineer/manager
if (engineer)
do engineer behavior
else
do manager behavior
Case 2: All 4
if (engineer)
if (hourly)
do engineer/hourly behavior
else
do engineer/salary behavior
else
if (hourly)
do manager/hourly behavior
else
do manager/salary behavior
Case 3: 3 cases
if (engineer)
do engineer behavior that doesn't care about hourly/salary
else
if (hourly)
do manager/hourly behavior
else
do manager/salary behavior
So these are the contrived cases that actually map to my real world
cases. There's not many, maybe only these three, but I'm wondering if
I should do something clever with the Strategy design pattern. Only
there are multiple type codes and the behavior sometimes depends on
both. I'm not sure how to cleanly separate that. Does anybody have
any suggestions? Leave as is? Only a Manager/Engineer Strategy since
all the cases depend on that distinction? Two Strategy hierarchies?
- Previous message: alAzif: "Re: Is it better to pass objects or discrete properties to methods?"
- Next in thread: kurbylogic_at_hotmail.com: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: kurbylogic_at_hotmail.com: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: H. S. Lahman: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: topmind: "Re: Strategy Pattern for Multiple Type Codes"
- Reply: Daniel T.: "Re: Strategy Pattern for Multiple Type Codes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]