πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      Which of the following design patterns is primarily used

      to create objects without specifying the exact class of object that will be created?
      A Singleton Correct Answer Incorrect Answer
      B Factory Method Correct Answer Incorrect Answer
      C Observer Correct Answer Incorrect Answer
      D Decorator Correct Answer Incorrect Answer
      E Strategy Correct Answer Incorrect Answer

      Solution

      The Factory Method design pattern is a creational pattern used to create objects without having to specify the exact class of object that will be instantiated. Instead of calling a constructor directly, the client uses a factory method to create an object. This pattern promotes loose coupling by allowing the code that uses the objects to depend on interfaces rather than concrete classes. The Factory Method provides a way to delegate the responsibility of instantiation to subclasses, which can decide which class to instantiate based on specific criteria or conditions. Option A (Singleton) is incorrect because the Singleton pattern restricts instantiation to a single instance of a class, not multiple types of objects. Option C (Observer) focuses on the relationship between objects to notify observers of state changes, not object creation. Option D (Decorator) is a structural pattern that adds behavior to objects dynamically, rather than creating them. Option E (Strategy) defines a family of algorithms, encapsulating each one, but does not deal with object creation.

      Practice Next

      Relevant for Exams:

      ask-question