Detecting new responsibilities while writing a class and what do you do about it?

43 views
Skip to first unread message

Lucidguppy

unread,
Feb 8, 2015, 11:07:39 AM2/8/15
to clean-code...@googlegroups.com
So your going along writing a class using TDD.  Do you have any triggers that help you realize your adding a new responsibility to the class as your coding?

After that - what do you do when you discover one?  Do you drop down a level and start coding the implementation, interface, and tests for that new responsibility?  Do you just write up the interface and mock it out for now?

Caio Fernando Paes de Andrade

unread,
Feb 8, 2015, 1:32:46 PM2/8/15
to clean-code...@googlegroups.com
If the newly discovered responsibility belongs to a higher layer, I switch to TDDing the new class.

If it belongs to a lower layer, I put a test double and keep working on the current class.

If it belongs to the same layer, I write the code in the same class and extract it later on, updating the tests too.

Caio

Sent from my iPhone

On 8 Feb 2015, at 14:07, Lucidguppy <matthew.j...@gmail.com> wrote:

So your going along writing a class using TDD.  Do you have any triggers that help you realize your adding a new responsibility to the class as your coding?

After that - what do you do when you discover one?  Do you drop down a level and start coding the implementation, interface, and tests for that new responsibility?  Do you just write up the interface and mock it out for now?

--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.

vivek poddar

unread,
Feb 8, 2015, 1:48:37 PM2/8/15
to clean-code...@googlegroups.com

Please provide some example code to let others see a clear picture.

George Dinwiddie

unread,
Feb 8, 2015, 2:42:57 PM2/8/15
to clean-code...@googlegroups.com
Lucid Guppy,
I often don't notice the new responsibility until it goes a little
further than a method or a field in the class where I'm working. I'll
generally then perform Extract Class to isolate it. Whether I flesh it
out first, or continue where I am, depends on mood. I just make sure I
make a note to do so.

I don't create an interface unless I need the flexibility of various
implementations.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Caio Fernando Bertoldi Paes de Andrade

unread,
Feb 9, 2015, 11:14:07 AM2/9/15
to clean-code...@googlegroups.com
Example code for all three cases would bloat this email, so I’ll give some more concrete general examples:

If the newly discovered responsibility belongs to a higher layer, I switch to TDDing the new class.

That’s when I’m TDDing an Usecase and a business rule seems to belong in an Entity. I’ll stop the Usecase, start TDDing the Entity and get back to the Usecase afterwards.

If it belongs to a lower layer, I put a test double and keep working on the current class.

That’s when I’m TDDing an Usecase and some logic seems to belong in a Gateway. I put a test double in place and continue TDDing the Usecase, going later to the real Gateway and implementing what’s needed.

If it belongs to the same layer, I write the code in the same class and extract it later on, updating the tests too.

That’s when I’m TDDing an Usecase and some logic feels duplicated among other Usecases or if I feel that this bit of logic is gonna be reused in the next Usecase I’ll write. I’ll resist the urge, continue TDDing the Usecase until I’m finished and I only extract the logic after I identify real need (duplication).

I hope it’s clearer now. :-)

Caio

On 8 Feb 2015, at 16:48, vivek poddar <vivek...@gmail.com> wrote:

Please provide some example code to let others see a clear picture.

On 9 Feb 2015 00:02, "Caio Fernando Paes de Andrade" <caio...@icloud.com> wrote:
If the newly discovered responsibility belongs to a higher layer, I switch to TDDing the new class.

If it belongs to a lower layer, I put a test double and keep working on the current class.



Reply all
Reply to author
Forward
0 new messages