This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How are design patterns different from algorithms? |
|
Answer» Both Design Patterns and ALGORITHMS describe TYPICAL solutions to any GIVEN problem. But the main difference is that the algorithm defines a clear set of actions for achieving a GOAL and a design pattern provides a high-level description of any solution. Design patterns applied to TWO different problems might be the same but the logic of implementation would be different and is based on the requirements. |
|
| 2. |
How are design principles different from design patterns? |
Answer»
|
|
| 3. |
What are some of the design patterns used in Java’s JDK library? |
|
Answer» FOLLOWING are some DESIGN patterns used in Java’s JDK library: |
|
| 4. |
What do you understand by the Open-Closed Principle (OCP)? |
|
Answer» The Open close principle states that any class, component or entity should be open for extension but closed for modification. A class can be extended via Inheritance, Interfaces, COMPOSITION whenever required instead of modifying the code of the class. Consider an INSTANCE where we have a class that calculates the area of a square. Later, we GET the requirement of calculating the area of a rectangle. Here, instead of modifying the ORIGINAL class, we can create one base class and this base class can be extended by the NEW class rectangle. |
|
| 5. |
What are the SOLID Principles? |
|
Answer» SOLID PRINCIPLES were the Object-Oriented principles introduced by Robert C. Martin in his paperwork “Design Principles and Design patterns” in the year 2000. The acronym for SOLID goes as follows:
|
|
| 6. |
What Is Gang of Four (GOF) in Design Patterns? |
|
Answer» Gang of Four (GOF) are the 4 superheroes who invented the concept of design patterns. These heroes are ERICH Gamma, Ralph JOHNSON, Richard HEL and John Vlissides. These people documented the design patterns in a book called “Design Patterns: ELEMENTS of Reusable Object-Oriented Software” in 1995. If not for these people, the software developers WOULD have wasted time-solving problems of recurring nature instead of focussing on business requirements. |
|
| 7. |
What is Inversion of Control? |
|
Answer» Inversion of control is a pattern used to decouple the dependencies between layers and components in the system. The DEPENDENCY-Injection (DI) pattern is an EXAMPLE of an IoC pattern that helps in removing dependencies in the code. Let us understand this with the help of an example. CONSIDER we have a class A that makes use of class B as shown below: public class A{ private B b; public A(){ this.b = new B(); }}Here, we have a dependency between classes A and B. If we had the IoC pattern implemented, we would not have used the new operator to assign value to the dependent variable. It would have been something as shown below: public class A { private IocB b; public A(IocB b) { this.b = b; }}We have inverted the control of HANDING the dependency of instantiating the object of class B to the IoC class IocB. |
|
| 8. |
What are the types of design patterns in Java? |
|
Answer» There are three types of design patterns. They are:
The following diagram represents the summary of the types of design patterns. |
|
| 9. |
How can you describe a design pattern? |
|
Answer» For describing a design PATTERN, we follow the below things:
|
|
| 10. |
What are the advantages of Java Design Patterns? |
|
Answer» Design patterns are TEMPLATE-based reusable solutions to help developers work EFFORTLESSLY in multiple projects. In Java, the design patterns are flexible and help to identify unwanted repetitive code easily. The architecture of the SOFTWARE can be customised as per the requirements. Some of the advantages of using design patterns in Java are:
|
|
| 11. |
What are design patterns? |
|
Answer» Design PATTERNS are the reusable solutions that solve common problems of software development. These problems include repetitive code, redundant functions and logic etc. These help to save considerable EFFORT and time required for the developers while developing software. Design patterns are commonly USED in object-oriented software products by incorporating best practices and PROMOTING REUSABILITY for developing robust code. |
|