Question
Which design pattern is best suited for managing the
creation of objects without specifying their concrete classes?Solution
The Factory Pattern is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created. It abstracts the instantiation process, enabling flexibility and scalability in object creation. For instance, in a GUI framework, the factory method might create different types of buttons (WindowsButton, MacButton) depending on the operating system. By decoupling the client code from concrete classes, this pattern promotes adherence to the Open/Closed Principle of SOLID. Why Other Options Are Incorrect :
- Singleton Pattern : This ensures a class has only one instance and provides global access to it, unrelated to flexible object creation.
- Observer Pattern : This defines a one-to-many dependency, where changes in one object are notified to multiple observers.
- Adapter Pattern : This works as a bridge between incompatible interfaces, not for object creation.
- Decorator Pattern : This adds functionality dynamically to objects, without modifying their structure.
A bag contains black and white balls, such that the probability of picking a black ball is 4/7. If the probability of picking two black balls without re...
A jar contains 6 pink, 2 black and 4 orange balls. If 3 balls are chosen at random without replacement, what is the probability that all 3 balls are of ...
A bag contains 3 black and 9 white balls. One ball is drawn at random. What is the probability that the ball drawn is white?
"A piggy bank comprises 5-rupee coins, 10-rupee coins, and 20-rupee coins. The quantity of 5-rupee coins in the piggy bank is 75% more than the number o...
- A jar contains six 50 paise coins, six Rs. 1 coins, and twelve Rs. 10 coins. One coin is lost. Find the probability that the lost coin is not a 50 paise co...
- Bag A contains 3 red, 4 black, 8 blue and 5 yellow balls. Bag B contains 5 red, 2 black, 4 blue and 3 yellow balls. Find the probability of drawing 2 blue ...
A box contains (x + 3) black balls, 6 yellow balls, and 5 orange balls. If two balls are selected at random and the probability of selecting two orange ...
Which of the following cannot be the probability of an event?
Find the probability that a number selected at random from first hundred number is a multiple of 3 or 5?Â
A game consists of tossing three coins once and then rolling two dice. Find the probability of getting exactly one tail in the coin toss and a sum equal...