dimanche 21 décembre 2014

What is the advantage of hiding new from clint by factory design pattern

I have read factory design pattern recently, in that he had mentioned one of the problem in normal approach is


*Need to use the new keyword in client classes.


So by using factory we have achieved this (client don't use new), but what is the advantage of hiding new from the client.


one problem is when client use new key word, he is the responsible to delete that memory. Any how if we use factory also, we need to do that, when client creates a object at the end client has to delete it(factory wont delete them).


I understand, other advantages like, reusing the existing code and no need to change client side code. but I got confused what we have achieved by hiding new (or even class) from client.


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire