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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<

1418


can inline function declare in private part of class?

3658


What is cohesion in oop?

624


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

1643


What are functions in oop?

586






What is solid in oops?

613


Why is oop better than procedural?

605


Prepare me a program for the animation of train

2000


How do you define a class in oop?

628


What are the benefits of interface?

582


What is destructor example?

597


What are the benefits of oop?

607


What is a class and object?

600


Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation

1662


What are the 4 pillars of oop?

673