Basic Design Pattern Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Sarvesh
S
Sarvesh
Community Contributor
Quizzes Created: 9 | Total Attempts: 71,992
Questions: 10 | Attempts: 9,224

SettingsSettingsSettings
Basic Design Pattern Trivia Quiz - Quiz

Welcome to the Basic Design Pattern Trivia Quiz. The quiz below is designed for all of us with a passion for design, and it offers you a chance to review some of the basic design patterns that one can use. Do you feel like you have done enough revision to tackle it? Do take up this quiz and see if that is true.


Questions and Answers
  • 1. 

    Defines an interface for creating an object, but let the subclasses decide which class to instantiate. It let the instantiation differ to subclasses.

    • A.

      Factory Method

    • B.

      Abstract Factory

    • C.

      Builder

    • D.

      Prototype

    Correct Answer
    A. Factory Method
    Explanation
    The Factory Method pattern defines an interface for creating an object, but allows subclasses to decide which class to instantiate. This pattern lets the instantiation differ to subclasses, meaning that each subclass can determine the specific object it wants to create. This promotes flexibility and extensibility in the code, as new subclasses can be easily added to create different types of objects without modifying the existing code.

    Rate this question:

  • 2. 

    Attach additional responsibilities to an object dynamically. It provides a flexible alternative to subclassing for extending functionality.

    • A.

      Chain of responsibility

    • B.

      Adapter

    • C.

      Decorator

    • D.

      Composite

    Correct Answer
    C. Decorator
    Explanation
    The Decorator pattern allows for the dynamic addition of responsibilities to an object at runtime, providing a flexible alternative to subclassing for extending functionality. This means that new behaviors can be added to an object without affecting its structure or the behavior of other objects in the system. The Decorator pattern is often used when there is a need to add or modify the behavior of an object without creating a new subclass.

    Rate this question:

  • 3. 

    Define a family of algorithms, encapsulate each one, and make them interchangeable. It lets the algorithm vary independently from clients that use it.

    • A.

      Template method

    • B.

      Decorator

    • C.

      Strategy

    • D.

      Visitor

    Correct Answer
    C. Strategy
    Explanation
    The Strategy pattern is the correct answer because it allows for the definition of a family of algorithms, encapsulation of each algorithm, and interchangeability between them. This pattern separates the algorithm implementation from the client code, allowing the algorithm to vary independently. The client can choose which algorithm to use at runtime, making it flexible and adaptable.

    Rate this question:

  • 4. 

    Define one too many dependencies between objects so that when one object changes state, all its dependencies are notified and updated automatically.

    • A.

      Chain of responsibility

    • B.

      Event Notification

    • C.

      Mediator

    • D.

      Observer

    Correct Answer
    D. Observer
    Explanation
    The Observer pattern is used to define one too many dependencies between objects, where when one object changes state, all its dependencies are notified and updated automatically. This pattern allows for loose coupling between objects, as the subject (the object being observed) does not need to have direct knowledge of its observers. Instead, the subject maintains a list of observers and notifies them when its state changes. This allows for a flexible and decoupled system, where objects can react to changes in the subject without having to be tightly coupled to it.

    Rate this question:

  • 5. 

    Encapsulate a request as an object, thereby letting you parametrize clients with different requests, queue or log requests, and support undoable operation.

    • A.

      Adapter

    • B.

      Command

    • C.

      Decorator

    • D.

      Composite

    Correct Answer
    B. Command
    Explanation
    The given statement describes the Command design pattern. In this pattern, a request is encapsulated as an object, allowing clients to be parametrized with different requests. It also enables queuing or logging of requests and supports undoable operations. The Command pattern helps in decoupling the sender of a request from the receiver, providing flexibility and extensibility to the system.

    Rate this question:

  • 6. 

    Ensure a class has only one instance, and provide a global access point to it.

    • A.

      Single Class Factory

    • B.

      Proxy

    • C.

      Singleton

    • D.

      Flyweight

    Correct Answer
    C. Singleton
    Explanation
    The correct answer is Singleton. Singleton is a design pattern that ensures a class has only one instance and provides a global access point to it. This pattern is useful when there should be only one instance of a class throughout the program and this instance needs to be accessible from different parts of the code. The Singleton pattern restricts the instantiation of a class to a single object and provides a way to access it globally.

    Rate this question:

  • 7. 

    Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. It lets subclasses redefine certain steps of an algorithm without changing the algorithm structure.

    • A.

      Chain of responsibility

    • B.

      Template method

    • C.

      Interpretor

    • D.

      Prototype

    Correct Answer
    B. Template method
    Explanation
    The given explanation correctly describes the concept of a template method. In the template method design pattern, the skeleton of an algorithm is defined in a base class, with certain steps deferred to subclasses. This allows subclasses to redefine or customize specific steps of the algorithm without altering the overall structure of the algorithm. This promotes code reuse and flexibility in designing related classes with similar behavior.

    Rate this question:

  • 8. 

    Provide a unified interface to a set of interfaces in a subsystem. It defines a higher level interface that makes the subsystem easier to use.

    • A.

      Facade

    • B.

      Mediator

    • C.

      Adapter

    • D.

      Strategy

    Correct Answer
    A. Facade
    Explanation
    A facade is a design pattern that provides a simplified interface to a complex system or set of interfaces. It acts as a unified interface that hides the complexities of the subsystem and makes it easier to use. It allows clients to interact with the subsystem through a single interface, instead of having to understand and interact with multiple interfaces. This simplifies the overall system architecture and improves usability.

    Rate this question:

  • 9. 

    Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

    • A.

      Iterator

    • B.

      Visitor

    • C.

      Composite

    • D.

      Command

    Correct Answer
    A. Iterator
    Explanation
    The Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. It allows clients to traverse the elements of a collection without knowing the specific structure of the collection. The Iterator interface defines methods like hasNext() to check if there are more elements, and next() to retrieve the next element in the sequence. This pattern promotes loose coupling between the client and the collection, as the client only needs to interact with the Iterator interface instead of the specific collection implementation.

    Rate this question:

  • 10. 

    Which of the following is correct about the Singleton design pattern.

    • A.

      This type of design pattern comes under creational pattern.

    • B.

      This pattern involves a single class which is responsible to create an object while making sure that only single object gets created.

    • C.

      Singleton class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class

    • D.

      All of the above.

    Correct Answer
    D. All of the above.
    Explanation
    The given answer, "All of the above," is correct because all three statements mentioned in the question are true about the Singleton design pattern. The Singleton design pattern is a creational pattern, meaning it is used to create objects. It involves a single class that is responsible for creating an object and ensures that only one instance of the object is created. The Singleton class also provides a way to access its only object directly without needing to instantiate the class. Therefore, all three statements are correct.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jul 29, 2008
    Quiz Created by
    Sarvesh
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.