Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
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."
๐ฎ Embracing the Cosmos | Prev. @ Indian Space Research Organisation (ISRO) - IIRS โข UCOST โข ICAR โข NIELIT | Masters in Data Science | UGC NET (CS)
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).
๐ฎ Embracing the Cosmos | Prev. @ Indian Space Research Organisation (ISRO) - IIRS โข UCOST โข ICAR โข NIELIT | Masters in Data Science | UGC NET (CS)
๐ฎ Embracing the Cosmos | Prev. @ Indian Space Research Organisation (ISRO) - IIRS โข UCOST โข ICAR โข NIELIT | Masters in Data Science | UGC NET (CS)
๐ฎ Embracing the Cosmos | Prev. @ Indian Space Research Organisation (ISRO) - IIRS โข UCOST โข ICAR โข NIELIT | Masters in Data Science | UGC NET (CS)
Top comments (7)
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."
Cool
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).
That's nice
My personal favourite is NULL PATTERN cause it saves me from writing extra code for handling exceptions and errors... What about u ?
I haven't had much opportunity to use it, but I think the state pattern is really cool. Has anyone here ever used it?
Not me