In what situation factory design patterns,DAO design
patterns,singleton design patterns should be applied.?

Answers were Sorted based on User's Feedback



In what situation factory design patterns,DAO design patterns,singleton design patterns should be a..

Answer / rajan

Unlike constructors, factory methods are not required to
create a new object each time they are invoked. Factory
methods can encapsulate the logic required to return a
singleton instance of the class requested, or they can
return an instance of the requested class from a pool of
instances.
Factory methods can return any subtype of the type
requested, and can require that clients refer to the
returned object by its interface, rather than the
implementation class. This enables an API to return objects
without making their classes public.
The class for the object returned by a factory method need
not even exist at the time the factory method is written.
This is one of the classic benefits of polymorphism: "old
code uses new code," which means that new classes can be
added, and their instances returned by the factory method,
without changing any of the existing code.

Is This Answer Correct ?    2 Yes 0 No

In what situation factory design patterns,DAO design patterns,singleton design patterns should be a..

Answer / monica

Use Factory Design Pattern when
- a class cannot anticipate the class of objects it must
create
- a class wants its subclasses to specify the objects it
creates
- classes delegate the responsibility to one of several
helper subclasses and you want to knowledge of which helper
subclass is the delegate.

Use Singleton Pattern when
- there must be one instance of a class and it must be
accessible to clients from well known access point.
-the sole instance should be extensible by subclassing, and
client should be able to use an extended instance without
modifying their code.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More OOPS Interview Questions

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; } 1) The computer will output "0123...99" 2) The computer will output "0123...100" 3) The output is undefined

7 Answers  


What is purpose of inheritance?

0 Answers  


Why is oop useful?

0 Answers  


what is SPL in c++.

1 Answers  


Why do we use virtual functions?

4 Answers  






Why do we use polymorphism in oops?

0 Answers  


Write a C++ program to conduct an election of a mayor.Declare a class ELECTION With the following specification: Data member: Name 25 character Age Integer symbol 1 character Member functions: To accept data for 20 contestant To accept symbol as voting from 100 voters. To declare the winner and the loser.

1 Answers   Global Academy, Infotech,


Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.

0 Answers  


#include <iostream> using namespace std; struct wow { int x; }; int main() { wow a; a.x = 22; int c = a.x; int *b = new int; cout << c; return 0; } option: No output 0 22 -(11) Will not compile

1 Answers   CTS, Wipro,


What is the default size allocated for array in the statement if size not specified " int a[] "

4 Answers   CTS,


What is the advantage of oop over procedural language?

0 Answers  


Write a program to sort the number with different sorts in one program ??

0 Answers   NIIT,


Categories