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 ! :-)
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.
发布评论
评论(3)
不,这并不过分。即使您的实际状态很少并且预计不会添加更多状态,使用状态模式也会使您的系统更易于测试,因为您可以单独测试各个状态。
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.
对于您的具体情况,我们不能说太多,因为您提供的信息太少。
但总的来说...
其他表达的意见可能有所不同,但是...
敏捷运动正在取得进展很大的力量。
他们会推荐YAGNI(你不需要它)。
这个想法是将复杂性推迟到以后,因为:
也就是说,如果你喜欢这个想法,那就去做吧,追随你的梦想! :-)
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 :
That said, if you enjoy the idea, go for it, follow your dreams ! :-)
你在谈论状态图吗?
无论如何,我想说,去吧。问题是将来您可能想要添加一个状态,然后认为不值得实现您的模式,因为它只是多了一个状态,对吧?然后你就有了 4 个状态,你必须添加另一个状态,然后重复这个过程。
然后你就进入了一种状态(双关语),你无法重构并使用状态模式,因为这会涉及重写太多代码。
所以,第一次就把事情做好。
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.