0

I've just read the book called clean code. The author Uncle Bob talks about a single responsibility that a function should have in a program. It should only do one thing.

Now, I would like to understand how is it now possible to reuse a code that does multiple things. Let's say I have a method called runTrafficAndCheckIfItPassed and it calls two methods inside of it: runTraffic and checkIfTrafficPassed.

Now let's say that in my software I need to run traffic and to check it's result in a lot of places in my software. sometimes i need to check that traffic has failed, and sometimes i need to check if it passed.

Why wouldn't it be right to call the runTrafficAndCheckIfItPassed function and why is it way better to call the functions inside separately?

As far as I see, if there will be a change in the runTraffic function, for example to receive another parameter, the change will be implemented in one place, only in runTrafficAndCheckIfItPassed, which we see will be kinda easy to maintain. But if i will use the functions seperately i will need to change it in any place. But Bob says it's wrong? Got any examples or tips why it is called wrong?

4
  • If everywhere you call RegisterAuser you also call ValidatedThatAuserisRegistered then it really isn't two things, is it? Commented Feb 14, 2019 at 23:38
  • I edited again, and it does two things. Commented Feb 14, 2019 at 23:44
  • 1
    Software Engineering is a better place to ask questions about software design principles. Commented Feb 14, 2019 at 23:52
  • alright ill check there too, thank you. Commented Feb 15, 2019 at 12:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.