250+ MCQs on The Generator Category, Factory Patterns and Singleton Patterns

Software Design Questions and Answers for Freshers on “The Generator Category,Factory Patterns and Singleton Patterns”.

1. Most object-oriented languages and systems provide which of these ways to create new objects?
a) Instantiating a class using one of its constructors
b) Cloning an existing object
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: All the mentioned are the two ways to create new objects.

2. Which of the following truly describes the structure of Generator pattern?
a) A generator pattern has a Client that needs an instance of a Product class
b) A Generator that creates or obtains access to such an instance on behalf of the Client
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: All of the mentioned are part of generator pattern structure.

3. Which of the following is true about factory method?
a) A factory method is a non-constructor operation that creates and returns class instances
b) Factory methods are widely used in mid-level design patterns and in object-oriented programming in general
c) Factory methods create new instances using constructors or cloning, so they do not rely on any special technique for class instantiation
d) All of the mentioned

Answer: d
Clarification: All the mentioned are true with respect to factory methods.

4. When a generator assumes responsibility for product object creation in a factory method,which of the following capabilities become available?
a) Access to product constructors can be restricted
b) Private data can be provided to new product objects
c) Product objects can be configured after creation
d) All of the mentioned

Answer: d
Clarification: All the mentioned are true for product object creation.

5. Which are the several reasons for using generator patterns?
a) Product Creation Control
b) Product Configuration Control
c) Client and Product Decoupling
d) All of the mentioned

Answer: d
Clarification: The several reasons are all mentioned.

6. The Factory patterns decouple clients from products by taking advantage of interfaces in two ways?
a) The generator class with the factory methods cannot be changed, disallowing variability in factory method implementations
b) Instances of a variety of classes that implement the product interface can be returned by a factory method, allowing great flexibility in results
c) All of the mentioned
d) None of the mentioned

Answer: b
Clarification: Generator class with the factory method can be changed.

7. What are the types of factory pattern?
a) Factory Method
b) Abstract Method
c) All of the mentioned
d) None of the mentioned

Answer: c
Clarification: There are two types of factory pattern- Factory,Abstract.

8. Which class that can have only one instance?
a) Adaptor Class
b) Proxy Class
c) Singleton Class
d) Factory class

Answer: c
Clarification: Singleton Class is the class that can have only one instance.

9. What are the drawbacks for singleton class?
a) Many languages do not allow classes to be values assignable to variables.
b) Singleton classes can be subclassed, and the singleton factory method can return a sub-class instance
c) Classes can easily replace only single instances
d) All of the internship

Answer: d
Clarification: All are the drawbacks for the singleton class.

10. Which of the following are true for the singleton class?
a) Singleton classes should be used whenever it is important that only a single instance of a class exist and that that single instance be widely accessible
b) The Singleton pattern can also be used, with slight modifications, when a limited number of instances greater than one are desired
c) Access restrictions are usually easy to add by restricting the visibility of either the class or the factory method
d) All of the mentioned

Answer: d
Clarification: All the mentioned are true for the singleton class.

Leave a Reply

Your email address will not be published. Required fields are marked *