DEV Community

Sharad Raj (He/Him)
Sharad Raj (He/Him)

Posted on

Name a DESIGN PATTERN and WHY u use it 😀 ?????

You got it .... let's discuss a bit more on design patterns here.....😁

Top comments (7)

Collapse
 
sargalias profile image
Spyros Argalias

I... Love the observer pattern.

I just find it so satisfying and elegant...

I don't use it with React because it's not needed, but with vanilla JavaScript when something needs an active "watcher" relationship to something else. Or in C# with events and delegates (which are basically the observer pattern).

Sidenote: I find it different to the pubsub pattern. For me pubsub is more like "I'll broadcast something and I don't care who is listening or why". Whereas observer seems like a more cohesive relationship to me. "This event is important, someone is exclusively interested. I'll notify them directly."

Collapse
 
sharadcodes profile image
Sharad Raj (He/Him)

Cool

Collapse
 
pclundaahl profile image
Patrick Charles-Lundaahl

Null object is definitely really cool!

I usually try to avoid using too many patterns - they can be really handy in a pinch, but most of my projects are pretty small, so I usually just try to pay attention to SRP and make sure things are small and composable. I've been slowly adopting more functional patterns, too, and I find that helps simplify things quite a lot.

I suppose the big one I tend to use is the façade pattern (helps with SRP). Others I've used a fair bit are Observable, along with a slightly-modified Service Locator (to get rid of the need to cast the results).

Collapse
 
sharadcodes profile image
Sharad Raj (He/Him)

That's nice

Collapse
 
pclundaahl profile image
Patrick Charles-Lundaahl

I haven't had much opportunity to use it, but I think the state pattern is really cool. Has anyone here ever used it?

Collapse
 
sharadcodes profile image
Sharad Raj (He/Him)

Not me

Collapse
 
sharadcodes profile image
Sharad Raj (He/Him) • Edited

My personal favourite is NULL PATTERN cause it saves me from writing extra code for handling exceptions and errors... What about u ?