What is the purpose of the Command design pattern?
- To create objects that are interchangeable with their base classes.
- To encapsulate operations in an object and pass them as messages.
- To manage the flow of control between objects in a complex system.
- To provide a way to invoke operations without coupling the invoker object to the target object that performs the operation.
The Command design pattern decouples the invoker of an operation from the target object that performs the operation. This allows for greater flexibility and modularity in the design of a system.
What is Flyweight pattern?
- A design pattern that allows objects with incompatible interfaces to work together by converting the interface of one object into an interface expected by the client
- 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 provides a simplified interface to a complex system, allowing the client to interact with the system through a single, unified interface
- A design pattern that uses shared objects to support large numbers of similar objects efficiently
Flyweight pattern is a design pattern that uses shared objects to support large numbers of similar objects efficiently. The pattern involves creating a shared object that can be used by multiple clients, reducing the amount of memory required to store the objects. This pattern can be useful in situations where you need to create large numbers of similar objects, but you want to minimize the memory footprint of the application.
What is an example of Adapter pattern?
- An example of Adapter pattern would be a TV with an HDMI port that needs to be connected to a DVD player with a composite video port. The adapter would convert the composite video output into HDMI, allowing the TV and DVD player to work together
- An example of Adapter pattern would be a computer mouse that uses a USB-A port, but the computer only has a USB-C port. The adapter would convert the USB-A port into USB-C, allowing the mouse to be used with the computer
- An example of Adapter pattern would be a laptop with a USB-C port that needs to be connected to a monitor with a VGA port. The adapter would convert the USB-C output into VGA, allowing the laptop and monitor to work together
- An example of Adapter pattern would be a mobile phone that uses a micro-USB port for charging, but the user has a charger with a lightning port. The adapter would convert the lightning port into micro-USB, allowing the mobile phone to be charged
An example of Adapter pattern would be a TV with an HDMI port that needs to be connected to a DVD player with a composite video port. The adapter would convert the composite video output into HDMI, allowing the TV and DVD player to work together. This example demonstrates the adapter pattern by showing how two objects with incompatible interfaces can work together through the use of an adapter.
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.