Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this questionIf something has only two to three states, is it overkill to use the St开发者_运维问答ate pattern?
No, it's not overkill. Even if you have few actual states and don't anticipate adding more, using the State pattern will make your system easier to test as you can test individual states in isolation.
We can't say much in your precise case, because your give too little information.
But in general ...
Other expressed opinions may differ, but ...
The Agile movement is gaining a lot of strengh. They would recommend YAGNI (You Aren't Gonna Need It).
The idea is to delay complexity until later, because :
- We developpers tend to love complexity, and sometimes put it where it is not needed.
- You will understand your code better later ; and then you might find a simpler solution.
- You user (or the person who specifies what to do, even if that is you) will have used your software later, so the requirements are likely to change. So any complexity anticipated might prove unusable at that point.
- Even in the (rare) case that you would later add exactly the same complexity that you would add now ... In the mean time, your code base is simpler, so your other coding activities are simpler and faster. That is also a gain.
- Also consider that your time is not infinite, and possibly someone pays for this (even you if it is your free time, or training time). Your effort might be more useful if spend on the current problem, rather that spending time for the future...
That said, if you enjoy the idea, go for it, follow your dreams ! :-)
are you talking about a state-chart?
Regardless, Id say go for it. The problem is in the future you might want to add a state, and then think its not worthwhile to implement your pattern because its just one more state, right? And then you've got 4 states, and you have to add another, and the process repeats.
And then you get to a state (pun-intended) where you can't refactor and use the states pattern because it would involve rewriting too much code.
So, do it right the first time.
精彩评论