DEV Community

Cover image for The 7 most important software design patterns

The 7 most important software design patterns

Fahim ul Haq on June 26, 2019

For a comprehensive deep-dive into the subject of Software Design Patterns, check out Software Design Patterns: Best Practices for Developers, crea...
Collapse
 
anpos231 profile image
anpos231

Keep in mind that Singletons and Observers are considered anti-patterns!

Collapse
 
themobiledev profile image
Chris McKay

I've never heard of Observer being an anti-pattern. If anything, it usually comes highly recommended in enterprise-level software as a way to reduce tight coupling between components.

I know that singleton is considered an anti-pattern, but on some smaller systems where dependency injection isn't available, it sure is useful.

Collapse
 
ccunnin297 profile image
Cole Cunningham

I've heard of singletons as anti-patterns, but observer as anti-pattern is new to me. Would you mind elaborating?

Collapse
 
wengelef profile image
Florian Wengelewski

Maybe he means Event Bus systems

Thread Thread
 
anpos231 profile image
anpos231

You are right, I was thinking what I just write, and seems like I got it wrong. The observer I had in mind was the observer you can find in Magento for example (Magento 2 docs)

Event Bus is bad,
Observer pattern is not.

Thread Thread
 
ewertonazevedo profile image
Ewerton Azevedo

I dont get why Event Bus is bad.

Collapse
 
malisbad profile image
Matt Williams

I think it's more like "can be" anti-patterns.

Collapse
 
luc45 profile image
Random Dev

Dependency Injection > Singleton

Collapse
 
anpos231 profile image
anpos231

Use DI to inject factories and use these factories to create new objects.

Collapse
 
andreasjakof profile image
Andreas Jakof • Edited

Welcome to my code ... well after I read Clean Code and refactored a lot.

200 Unit Tests and still incoming 😎

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

Singleton is good pattern for create NullObject.

Observer is good for make loggers.