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 Adapter Pattern?
- The Adapter pattern is a design pattern used to aggregate several classes into a single class to simplify the management and organization of code.
- The Adapter pattern is a design pattern used to convert the interface of one class into another interface that a client is expecting. This allows classes with incompatible interfaces to work together.
- The Adapter pattern is a design pattern used to create new objects from existing ones by modifying their properties or behavior.
- The Adapter pattern is a design pattern used to modify the behavior of an existing class to make it meet the requirements of a different interface.
The Adapter pattern is a design pattern used to convert the interface of one class into another interface that a client is expecting. This allows classes with incompatible interfaces to work together.
What is the purpose of the Command pattern?
- To allow objects to be treated as commands that can be executed, deferred or queued
- To create complex objects step by step, using a builder object to abstract the process of creating the object
- To provide a common interface for a group of related classes
- To provide a simplified interface to a complex system, hiding the complexity of the system behind a single interface
The Command pattern allows objects to be treated as commands that can be executed, deferred or queued
What is the difference between the Abstract Factory and Factory patterns?
- The Abstract Factory pattern is used to create objects without specifying the exact class of object that will be created, while the Factory pattern is used to provide an interface for creating families of related or dependent objects.
- The Abstract Factory pattern is used to create singleton objects, while the Factory pattern is used to create objects without specifying the exact class of object that will be created.
- The Abstract Factory pattern is used to provide a generic interface for creating objects, while the Factory pattern is used to provide a specific interface for creating objects.
- The Abstract Factory pattern is used to provide an interface for creating families of related or dependent objects, while the Factory pattern is used to create objects without specifying the exact class of object that will be created.
The Abstract Factory pattern is used to provide an interface for creating families of related or dependent objects, while the Factory pattern is used to create objects without specifying the exact class of object that will be created.