Oleg Varaksin
Sep 8, 2024

I thought exactly about this and didn't understand why we need ServiceLocatorPattern. There is also a third approach, called Strategy Pattern: just inject a list with Parsers List<Parser> parsers, define a method boolean match(ContentType) (acts as Predicate) on Parser interface and make sure every Parser implements it. The concrete Parser can be resolved as parser = parsers.stream().filter(parser -> parser.match(contentType)).findFirst().orElse(null). Sure, the approach with the Map is the best one because you don't need to iterrate over Parser impl.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Oleg Varaksin
Oleg Varaksin

Written by Oleg Varaksin

Thoughts on software development. Author of “PrimeFaces Cookbook” and “Angular UI Development with PrimeNG”. My old blog: http://ovaraksin.blogspot.de

No responses yet

Write a response