Java Design Patterns Interview Question

Connect with

Java Design Patterns Interview QuestionsJava Design patterns interview questions is one of the FAQ for more 5 years of experience. strategy pattern, state desing pattern, solve your design issue.

1. When to use Strategy Design Pattern in Java?

Strategy pattern is quite useful for implementing a set of related algorithms e.g. different compression algorithms, different ways of the logger, etc. Strategy pattern used object composition, which allows switching algorithm run time.

This pattern follows the open closed design principle and quite useful in Java. One example of a Strategy pattern from JDK itself is a Collections.sort() method and Comparator interface, which is a strategy interface and defines the strategy for comparing objects.

2. Difference between Strategy and State design Pattern in Java?

This is an interesting Java design pattern interview questions, why this is interesting because both Strategy and State pattern have the same structure it means both UML diagram looks exactly same. UML class diagrams for both patterns look exactly the same, but their intent is totally different.

A state design pattern is used to define and manage the state of the object, while a Strategy pattern is used to define a set of interchangeable algorithms and lets a client choose one of them. You can say Strategy pattern is a client-driven pattern while Objects can manage their state itself.

3. Does each subsystem have only one facade?

It’s not necessarily, The pattern certainly allows for any number of the facade to be created for a given subsystem.

4. is there anyway, the client can know about the proxy class or not?

Yes, the proxy class has a static method called isProxyClass(). This method returns true if the class is a dynamic proxy class. other than class act as a normal class that implements an interface.

I hope you enjoyed this post of behavioral design patterns, and you can visit design patterns tutorial for more details


Connect with

Leave a Comment

Your email address will not be published. Required fields are marked *