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 has 4 red, 3 blue, and 3 green balls. Two are drawn without replacement. Find probability that both are of different colors.
- The letters of the word MISCHIEF are arranged among themselves. What is the probability that word ICE will be contained?
One bag contains 5 yellow hats and 4pink hats. Another bag contains 3 yellow hats and 7pink hats. If one hat is drawn from each bag, what is the probabi...
17 rotten bananas are accidentally mixed with 120 good ones. It is not possible to just look at a banana and tell whether or not it is rotten. One banan...
One five letter word is to be formed taking all letters – U, Z, M, O and Q. What is the probability that this is word formed will contain all vowe...
A bag has 7 pink, 4 black and 3 yellow balls while another bag has 5 pink, 6 yellow and 3 blue balls. A bag is selected at random and a ball drawn out ...
The probability of selecting a rotten egg randomly from a basket of 250 eggs is 0.2. What is the number of rotten eggs in the basket?
16 rotten bananas are accidentally mixed with 155 good ones. It is not possible to just look at a banana and tell whether or not it is rotten. One banan...
- A container holds 7 orange balls, 5 violet balls and 8 grey balls. Two balls are drawn at random. What is the probability that at least one of them is viol...
A box has βxβ black marbles, βx + 5β blue marbles and βx β 1β yellow marbles. If the probability of selecting a yellow marble is 1/28 less...