Skip to content
Advertisement

What is the name of the design pattern where I dynamically pick the correct implementation based on data?

Originally I picked the correct User implementation, based on domain and realm data from the Java EE server. However that was company code, so I had to rewrite the example with numbers. I hope the underlying pattern is still understandable though. For those unfamiliar with CDI, @Inject Instance allows you to iterate through all implementations of an interface.

JavaScript

Advertisement

Answer

I think you are talking about the Strategy Pattern:

JavaScript

Then you have your list of strategies:

JavaScript

Thus:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement