7 ms·
The post also presents a false choice between what’s known as “the singleton pattern” versus just allocating a single instance of the object and passing it arou
by brown9-2 6y ago
The post also presents a false choice between what’s known as “the singleton pattern” versus just allocating a single instance of the object and passing it around where needed:
> We don’t write a lot of these because our code doesn’t follow standard decoupling practices; while those principles make for easy to maintain code for a team, they add extra steps during runtime, and allocate more memory. It’s not much on any given transaction, but over thousands per second, it adds up. Things like polymorphism and dependency injection have been replaced with static fields and service locators.
“dependency injection” doesn’t require constantly allocating new instances of the things your classes need.