Software Design Questions and Answers – The Generator Category, Factory Patterns and Singleton Patterns

This set of Software Design Questions and Answers for Freshers focuses 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

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

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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: d
Explanation: The several reasons are all mentioned.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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
View Answer

Answer: b
Explanation: 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
View Answer

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

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

Answer: c
Explanation: 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
View Answer

Answer: d
Explanation: All are the drawbacks for the singleton class.
advertisement

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
View Answer

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

Sanfoundry Global Education & Learning Series – Software Architecture and Design.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.