What is Adapter 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 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 promotes the loose coupling between objects, making the system easier to maintain and extend
Adapter pattern is 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. This pattern involves creating a wrapper class that implements the target interface and delegates calls to the adaptee object. The adapter acts as a bridge between the adaptee and client, allowing them to work together even if their interfaces are not compatible.

What is the purpose of the Command pattern?

  • To allow for loose coupling between the sender of a request and its receivers.
  • To allow sending requests to objects without knowing anything about the operation being requested or the receiver of the request.
  • To convert the interface of a class into another interface clients expect.
  • To provide a unified interface to a set of interfaces in a subsystem.
The Command pattern is used to allow sending requests to objects without knowing anything about the operation being requested or the receiver of the request. It provides a way to queue or log requests and acts as a marshal between the sender and the receiver.

What will you choose: Repository Pattern or "smart" business objects?

  • It depends on the complexity of the project, but in general "smart" business objects is a better choice as it allows for easier management of business logic.
  • It depends on the requirements of the project, but in general Repository Pattern is a better choice as it provides separation of concerns between the data access and business logic.
  • It depends on the size of the project, but in general "smart" business objects is a better choice as it reduces the number of classes needed.
  • It depends on the team's experience, but in general Repository Pattern is a better choice as it provides a common interface for data access.
The choice between Repository Pattern and "smart" business objects depends on the specific requirements of the project, but in general the Repository Pattern provides better separation of concerns and a common interface for data access.

What is State pattern?

  • A design pattern in which an object, called the composite, is composed of one-to-many other objects, in a tree-like structure, allowing the client to interact with individual objects and compositions of objects uniformly
  • A design pattern in which an object, called the context, holds a reference to an instance of one of several possible concrete state objects, each of which represents a distinct state of the context and implements a common state interface
  • A design pattern in which an object, called the decorator, adds or overrides behavior of an existing object, dynamically
  • A design pattern in which an object, called the prototype, is used as a template to create new objects, without specifying their concrete classes
The State pattern is a design pattern in which an object, called the context, holds a reference to an instance of one of several possible concrete state objects, each of which represents a distinct state of the context and implements a common state interface. The State pattern allows the context's behavior to be altered dynamically by changing its state. The State pattern is used to implement state machines, allowing an object's behavior to be altered as its internal state changes.

What are the difference between a Static class and a Singleton class?

  • A Static class can have instance methods and properties, while a Singleton class can only have static methods and properties.
  • A Static class can have multiple instances, while a Singleton class can have only one instance.
  • A Static class does not maintain state, while a Singleton class maintains state for a single instance.
  • A Static class is a class that cannot be instantiated, while a Singleton class can be instantiated only once.
A Static class is a class that cannot be instantiated and can only have static members. It is a sealed class, which means it cannot be inherited. A Singleton class is a design pattern that ensures a class has only one instance while providing a global point of access to this instance. It uses a private constructor and a static instance variable to ensure that only one instance can be created. Unlike a Static class, a Singleton class can have both static and instance members.

Can we use CQRS without Event Sourcing?

  • No, CQRS and Event Sourcing are tightly coupled and cannot be used separately.
  • No, CQRS requires Event Sourcing to function properly.
  • Yes, CQRS and Event Sourcing are separate patterns and can be used independently of each other. CQRS can be used without Event Sourcing, but Event Sourcing can provide benefits in terms of versioning and auditing.
  • Yes, but the benefits of CQRS will not be fully realized without Event Sourcing.
CQRS and Event Sourcing are separate patterns and can be used independently of each other. However, using Event Sourcing with CQRS can provide benefits in terms of versioning and auditing.

What are the main categories of Design Patterns?

  • Behavioral, Management, and Maintenance
  • Creational, Structural, and Behavioral
  • Presentational, Container, and Behavioral
  • Structural, Logical, and Physical
Design Patterns are usually categorized into three types: Creational, Structural, and Behavioral. Creational patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Structural patterns deal with object composition, creating relationships between objects to form larger structures. Behavioral patterns focus on communication between objects, what goes on between objects and how they operate together.

What is the purpose of the Memento pattern?

  • The Memento pattern is used to provide access control to an object's internal state.
  • The Memento pattern is used to store the state of an object in a database so that it can be restored later.
  • The Memento pattern is used to store the state of an object so that it can be restored later.
  • The Memento pattern is used to store the state of multiple objects so that they can be restored later.
The Memento pattern is used to store the state of an object so that it can be restored later.

What is the difference between Strategy design pattern and State design pattern?

  • Strategy pattern is used for behavior that can change at runtime, State pattern is used for behavior that changes based on the state of the object.
  • Strategy pattern is used to change the behavior of an object based on its state, State pattern is used to change the behavior of an object at runtime.
  • Strategy pattern is used to change the behavior of an object based on the context, State pattern is used to define a set of states and transition between them.
  • Strategy pattern is used to define a set of algorithms, State pattern is used to change the behavior of an object based on its internal state.
The Strategy design pattern allows an object to change its behavior at runtime, while the State design pattern changes the behavior of an object based on its internal state.

How to prevent cloning of a singleton object in Java?

  • By declaring the class as final
  • By declaring the clone method as final
  • By declaring the clone method as private
  • By throwing a CloneNotSupportedException in the clone method
The best way to prevent cloning of a singleton object in Java is by throwing a CloneNotSupportedException in the clone method. This will make the class not cloneable and prevent other objects from attempting to create a copy of the singleton object.