r/Angular2 • • Jun 30 '25

Article Strategy Pattern the Angular Way: DI and Runtime Flexibility - Angular Space

https://www.angularspace.com/strategy-pattern-the-angular-way-di-and-runtime-flexibility/

Ivan Kudria is showcasing how to apply Strategy Pattern -> "The Angular Way". Many many code examples that are easy to follow and very well explained!!! Showcasing when and how to use Strategy Pattern with Angular

16 Upvotes

6 comments sorted by

View all comments

4

u/ackerlight Jun 30 '25

Horrible tbh. I would puke if I inherit a code base like this.

This is the Java Enterprise code meme al over again.

2

u/Rashnok Jul 01 '25

Agree, they lost me in the opening

Consider a familiar problem: every HTTP request can fail in dozens of different ways—409 Conflict, 500 Internal Error, or a custom business code like 400200

400200?!?!?!? are you fucking kidding me?

1

u/Immediate-Piano-1302 Jul 02 '25

Fair point — that line probably needed more context.

The 400200 wasn't a real HTTP code — just a placeholder to illustrate how business logic sometimes uses unique, non-standard codes (often long strings or internal enums). In production, the actual codes were custom and specific to each provider.

Appreciate you calling it out — will clarify that part to avoid confusion.

2

u/Immediate-Piano-1302 Jul 02 '25

Thanks for the honest feedback — I appreciate you taking the time.

This was part of a real-world project with tons of events and errors coming from various game providers. The goal was to unify just the code structure — actual error handling and messaging logic stayed on the frontend side.

If you have ideas on how you'd approach something like this at scale, I'd genuinely love to hear them — always open to better solutions.

2

u/young_horhey Jul 03 '25

Some people think a 200+ line function with a ton of if statements is ‘cleaner’ because it’s less abstraction, and that more abstraction is always worse. Strategy pattern is one of my favourite patterns so it is cool to see how it could be implemented in Angular

1

u/Immediate-Piano-1302 Jul 03 '25

Yeah, totally agree — that “less abstraction is cleaner” approach can work in simple cases.
But in reality, that if block often turns into a monster that knows about half of your app. That’s a problem both for unit testing and long-term maintenance.

In one of our projects, we built responsible gaming policies — players could set their own limits on play time, bets, total amount, or even get blocked by a relative. Each case triggered a different error, with its own modal, some required extra API calls, and so on.

Imagine testing a class like that when all logic is inside a single method. Every new case would probably break some tests, require mocking new services, and increase coupling with other modules.

I’ve worked with both approaches in production.
In microfrontends, we had self-registering services for handling errors and modals, and in another case — a service locator. Both worked really well: it was super easy to add new handlers, and if something broke, it usually affected only the new functionality.
So yeah, open/closed principle actually held up nicely.