Thursday, 15 September 2011

Maximum number of states in State Pattern -



Maximum number of states in State Pattern -

i trying utilize state pattern , have question. state pattern designed situtations limited number of states this:

tcpstate: 1- tcpestablished 2- tcplisenting 3- tcpclosed etc.

or can used in cases hundreds of states illustration employee in employee attendance scheme employee have composite state of multiple components number of yearly vacations has in balance, number of hours should compensate month, state represent hourly salary rate depending on work load month, etc. each employee can have combination of multiple attributes considered state behavior.

at case there hundrerds of state objects, right thing do? how manage state objects naming? , if illustration 1 3rd of states share behavior method, , quarter shares behavior method etc. i.e. not states necisserly have unique behavior in it's methods. dont think copying implementation , pasting states have same behavior mutual method wise!

thank much.

there no defined maximum number of 'state' classes, if implement 'state' class every 'state' end massive code duplication, considered problem on own.

note 'state' in a combination of assigned values not same 'state' class in state pattern, implementation of set of abstract methods. misnomer if inquire me, 'state' should improve called 'behaviour' in pattern.

if can capture behaviour in limited set of 'state' classes (i.e. if can built limited number of lines of code, yes) can apply state pattern. mention, can apply state pattern multiple times, maintaining more 1 active states.

design-patterns state max composite

No comments:

Post a Comment