paint-brush
The Lack of Internal State and How it Makes Your Classes Easier to Test and Refactorby@marcinwosinek
191 reads

The Lack of Internal State and How it Makes Your Classes Easier to Test and Refactor

by Marcin Wosinek4mMay 5th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Test-driven development (TDD) or just writing tests can make your code better. Let’s take a look at this effect with a simple example: moving an internal state of a class to a dependency. The most straightforward way of keeping a state is to add a private variable and put aside the values you need for later use. This will do the job, but it makes testing more difficult. To make the code more testable, we can define a separate class that will keep the state.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - The Lack of Internal State and How it Makes Your Classes Easier to Test and Refactor
Marcin Wosinek HackerNoon profile picture
Marcin Wosinek

Marcin Wosinek

@marcinwosinek

I'm a JavaScript developer. I'm here to teach you useful skills, so you can succeed in your work & private projects.

Learn More
LEARN MORE ABOUT @MARCINWOSINEK'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Marcin Wosinek HackerNoon profile picture
Marcin Wosinek@marcinwosinek
I'm a JavaScript developer. I'm here to teach you useful skills, so you can succeed in your work & private projects.

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Grimneko
Social
Moooi
Jakobs
Hyperborea
Nitter
Seachengineeringjobs
Ktachibana
Zeitverschreib
Mastodon
100yenmac
Codytechs
Tokhmi