Skip to main content

C++ Design Patterns

1).What is a design pattern in C++?

1) A reusable solution to a common problem
2) A specific algorithm
3) A C++ feature
4) None of the above

2).Which of the following is a structural design pattern?

1) Observer
2) Decorator
3) Factory
4) None of the above

3).What is the purpose of the Singleton design pattern?

1) To ensure a class has only one instance
2) To allow multiple instances of a class
3) To hide the implementation details
4) None of the above

4).Which design pattern is used to create objects without specifying the exact class?

1) Factory Method
2) Singleton
3) Abstract Factory
4) None of the above

5).Which design pattern is used to provide a way to access elements of a collection without exposing the underlying structure?

1) Iterator
2) Observer
3) Decorator
4) None of the above

6).What is the purpose of the Observer design pattern?

1) To allow an object to notify other objects about changes
2) To control the creation of objects
3) To represent a hierarchy of classes
4) None of the above

7).Which design pattern is used to add new functionality to an object without changing its structure?

1) Decorator
2) Strategy
3) Composite
4) None of the above

8).Which of the following is an example of a behavioral design pattern?

1) Observer
2) Abstract Factory
3) Prototype
4) None of the above

9).Which design pattern is used to represent part-whole hierarchies?

1) Composite
2) Strategy
3) Chain of Responsibility
4) None of the above

10).Which design pattern allows an object to behave differently based on its internal state?

1) State
2) Factory Method
3) Singleton
4) None of the above