Interview Questions and Answers For Design Patterns
by Bhavya Sri, on May 27, 2017 12:13:35 PM
Q1. What is Design Pattern?
Ans: Design Pattern In software is a best practice a general, reusable solution to a common problem faced by software developers within a given context in software design.
Design patterns are best practices that programmer can use to solve common problems when designing a system or application.
Q2. What are the types of Design Patterns?
Ans: Creational Patterns
Structural Patterns
Behavioral Patterns
Q3. What is meant by Gang of Four GOF?
Ans: The four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides These authors are collectively known as Gang of Four GOF.
These initiated the concept of Design Pattern in Software development In 1994 & published a book titled Design Patterns - Elements of Reusable Object-Oriented Software
Q4. What are J2EE Patterns?
Ans: J2EE Patterns concerned with the presentation tier.
Q5. What is Factory pattern?
Ans: Factory pattern is one of the most used design patterns in Java. ... In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.
Q6. Can we create a clone of a singleton object?
Ans: Yes
Q7. How to create Singleton class in java?
- First, make the constructor private so that new operator cannot be used to instantiate the class.
- Return an object of the object if not null otherwise create the object and return the same via a method.
Q8.What is the benefit of Factory pattern?
Ans: Factory pattern encapsulates the implementation details and underlying implementation can be changed without any impact on caller api.
Q9. What is Singleton pattern?
Ans: In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.
Q10. What is Abstract Factory pattern?
Ans: Abstract factory pattern is also called factory of factories.The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes.
Q11. How to prevent cloning of a singleton object?
Ans: By Throwing exception within the body of clone method.