InvoiceProvider obj = new InternalInvoiceProvider(); obj.PrintInvoice(); obj = new ExternalInvoiceProvider(); obj.PrintInvoice(); It will also execute two PrintInvoice method of two different class with single object, then why we have to follow all. Please explain, waiting for the reply
Using strategy pattern you don't have to reinitialize the obj variable. This may be required in some scenarios where you want to preserve the state of the object. See dofactory.com/net/strategy-design-pattern real world example.
@@net-programmer I got the point that we are passing a different class name in the SetStrategy method of context class.But my question is that we can achieve desire output with the help of re-initialization, without any SetStrategy method of any context class.
Thanks! That was really helpful. I recently took part in recruiting challenge that needed a strategy pattern, and it really is helpful this strategy.
are you free to help with my project now?
InvoiceProvider obj = new InternalInvoiceProvider();
obj.PrintInvoice();
obj = new ExternalInvoiceProvider();
obj.PrintInvoice();
It will also execute two PrintInvoice method of two different class with single object, then why we have to follow all. Please explain, waiting for the reply
Using strategy pattern you don't have to reinitialize the obj variable. This may be required in some scenarios where you want to preserve the state of the object. See dofactory.com/net/strategy-design-pattern real world example.
@@net-programmer I got the point that we are passing a different class name in the SetStrategy method of context class.But my question is that we can achieve desire output with the help of re-initialization, without any SetStrategy method of any context class.
promo sm 🙃