Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 seems.

Thanks

like image 764
GurdeepS Avatar asked Apr 26 '10 08:04

GurdeepS


3 Answers

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.

like image 90
Daniel Daranas Avatar answered Oct 14 '22 09:10

Daniel Daranas


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.

like image 30
Wildcat Avatar answered Oct 14 '22 09:10

Wildcat


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.

like image 1
mcintyre321 Avatar answered Oct 14 '22 09:10

mcintyre321