Tension between the dependency inversion principle and avoiding "new" in C++?
Posted
by
Kazark
on Programmers
See other posts from Programmers
or by Kazark
Published on 2012-11-27T20:43:14Z
Indexed on
2012/11/27
23:28 UTC
Read the original article
Hit count: 223
I have seen a lot of advice that it is better to do Type object;
than Type* object = new Type();
in C++ whenever possible. I understand the rational behind this and appreciate it.
But according to my understanding, to practice dependency inversion requires pointers, e.g.: Type* object = new Implementation();
. (Or am I wrong about that?)
Is there an inherent tension between the DIP and avoiding new
when using C++? If so, what patterns/principles/practices can be used to mitigate this tension?
© Programmers or respective owner