Coding Blocks cover image

Design Patterns Part 1 – You Create Me!

Coding Blocks

00:00

Is the Singleton Pattern Difficult to Test?

The singleton pattern can be used to store a variable that some user input, and then you want to carry it throughout the rest of your application. The biggest problem I have with it is testing. You're literally like kind of cementing this concrete class into your input into your calling code. They're not tightly coupled. So if you've got a unit test that does some stuff and it modifies the state of that singleton, then you need to make sure in all those tests that you reset that state back to where you expected to be when you run. It's just something to kind of watch out for.

Play episode from 01:19:02
Transcript

The AI-powered Podcast Player

Save insights by tapping your headphones, chat with episodes, discover the best highlights - and more!
App store bannerPlay store banner
Get the app