开发者

Sequential coupling in code

Is sequential coupling really a bad thing in code?

Although it's an anti-pattern, the only risk I see is calling methods in the wrong order but documentation of an API/class library with this anti-pattern should take care of that. What other problems are there from code which is sequential? Also, this pattern could easily be fixed by using a facade it 开发者_Go百科seems.

Thanks


It is an antipattern to just ignore a method call because something which shouldn't have been done before hasn't.

This should be controlled using design by contract. Failed preconditions typically raise a failed precondition exception, which is basically the software yelling at you if you use the class in the wrong way. They are superior to written documentation.


Even in Wiki article you mentioned there is an opinion that

This may be an anti-pattern, depending on context.

In many cases there is no other way. Eventually we use algorithms to solve tasks. And they are by definition

an effective methods for solving a problem using a finite sequence of instructions

Sometimes it's possible to hide this sequence. But not always.


its a minor anti pattern, as if the documentation is bad (or the api is confusing) you can get things into a bad states. Its like a recipe where it only tells you to put the yolks aside after you've already beaten the eggs together.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜