What is the difference between a Singleton and a Prototype pattern?
- None of the above
- The Singleton and Prototype patterns are the same
- The Singleton pattern creates multiple instances, while the Prototype pattern creates only one instance
- The Singleton pattern creates only one instance, while the Prototype pattern creates multiple instances
The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance, while the Prototype pattern provides a mechanism for creating object instances that are exact copies of a prototype object
Name some of the design patterns used in JDK library.
- Abstract Factory, Builder, Factory Method, Singleton
- Adapter, Facade, Observer, Prototype
- Chain of Responsibility, Command, Interpreter, Iterator
- Decorator, Mediator, State, Strategy
Some of the design patterns used in the JDK library include Decorator, Mediator, State, and Strategy. These patterns are used in various classes and APIs of the Java Standard Library to provide a clean and efficient implementation of common design problems.
How can you create Singleton class in Java?
- By declaring a private constructor and a public static method that returns the only instance of the class
- By declaring all of its variables and methods as final
- By declaring all of its variables and methods as static
- By implementing the Cloneable interface
A Singleton class in Java can be created by declaring a private constructor and a public static method that returns the only instance of the class. This ensures that there is only one instance of the class in the JVM and that it can be easily accessed by other objects in the system.
What is the purpose of the MVC pattern?
- The Model-View-Controller (MVC) pattern is used to create a modular and scalable code structure. The Model represents the data, the View displays the data, and the Controller handles user interactions and updates the Model.
- The Model-View-Controller (MVC) pattern is used to create a simple, flexible and reusable code structure. The Model represents the data, the View displays the data, and the Controller handles user interactions and updates the Model.
- The Model-View-Controller (MVC) pattern is used to provide a common interface for accessing application data. The Model represents the data, the View displays the data, and the Controller manages the flow of data between the Model and the View.
- The Model-View-Controller (MVC) pattern is used to separate application logic from presentation logic and data management. The Model represents the data, the View displays the data, and the Controller manages the flow of data between the Model and the View.
The MVC pattern separates application logic into three distinct components, the Model, View and Controller, in order to create a flexible, reusable and scalable code structure.
What is the Deadly Diamond of Death?
- The Deadly Diamond of Death is a situation in which a class has too many responsibilities and becomes overly complex.
- The Deadly Diamond of Death is a situation in which a class inherits from two classes with conflicting attributes.
- The Deadly Diamond of Death is a situation in which a class inherits from two classes with conflicting implementations of a method.
- The Deadly Diamond of Death is a situation in which multiple inheritance results in ambiguity and complexity in the inheritance hierarchy of a system.
The Deadly Diamond of Death is a situation in which multiple inheritance results in ambiguity and complexity in the inheritance hierarchy of a system. This can lead to difficulty in maintaining the system and understanding its behavior.
What is the difference between the Bridge and Filter patterns?
- The Bridge pattern allows for loose coupling between the sender of a request and its receivers, while the Filter pattern provides a unified interface to a set of interfaces in a subsystem.
- The Bridge pattern decouples an abstraction from its implementation, allowing the two to vary independently. The Filter pattern provides a way to filter requests that pass through a set of handlers.
- The Bridge pattern is used to create objects based on a blueprint, while the Filter pattern provides a way to convert the interface of a class into another interface clients expect.
- The Bridge pattern is used to filter requests that pass through a set of handlers, while the Filter pattern decouples an abstraction from its implementation.
The Bridge pattern decouples an abstraction from its implementation, allowing the two to vary independently, while the Filter pattern provides a way to filter requests that pass through a set of handlers.
What is Prototype pattern?
- A design pattern that creates objects by cloning existing objects, rather than creating new instances from scratch
- A design pattern that creates objects in a step-by-step manner, allowing for more control over the object creation process
- A design pattern that helps to reduce the number of objects in the system, making it more efficient
- A design pattern that promotes the loose coupling between objects, making the system easier to maintain and extend
Prototype pattern is a design pattern that creates objects by cloning existing objects, rather than creating new instances from scratch. This pattern involves implementing a prototype interface, which is used to create a new instance of the object. The new instance is a copy of the existing object, with any changes made to the copy not affecting the original.
What is the difference between the Adapter and Bridge patterns?
- None of the above
- The Adapter and Bridge patterns are the same
- The Adapter pattern converts the interface of one class into another, while the Bridge pattern decouples an abstraction from its implementation, allowing the two to be varied independently
- The Adapter pattern decouples an abstraction from its implementation, while the Bridge pattern converts the interface of one class into another
The Adapter pattern converts the interface of one class into another, while the Bridge pattern decouples an abstraction from its implementation, allowing the two to be varied independently
What is the difference between the Template patterns and the Strategy pattern?
- Template patterns allow for the implementation of a specific algorithm to be swapped out at runtime, while Strategy patterns provide a set of steps to be followed in a defined order. Template patterns are meant to be composed, while Strategy patterns are meant to be subclassed.
- Template patterns and Strategy patterns are the same thing.
- Template patterns and Strategy patterns have no relationship to each other.
- Template patterns provide a set of steps to be followed in a defined order, while Strategy patterns allow for the implementation of a specific algorithm to be swapped out at runtime. Template patterns are meant to be subclassed, while Strategy patterns are meant to be composed.
The Template pattern provides a set of steps to be followed in a defined order, while the Strategy pattern allows for the implementation of a specific algorithm to be swapped out at runtime. Template patterns are meant to be subclassed, while Strategy patterns are meant to be composed.
What are Design Patterns?
- A coding style that emphasizes using a specific way of writing code to make it more maintainable and readable.
- A design principle that focuses on creating software that is aesthetically pleasing and easy to use.
- A methodology for software development that involves following a set of steps to develop software.
- A set of predefined solutions to common problems in software development that provide a common vocabulary and a standard way of thinking about a particular problem.
Design patterns are reusable solutions to common problems that arise in software development. They provide a common vocabulary and a standard way of thinking about a particular problem, making it easier for software developers to communicate and collaborate. Design patterns are not specific to any programming language and can be applied to different programming paradigms, including object-oriented programming.