On 9/23/15 9:48 AM, Ola Fosheim Grøstad wrote:
On Wednesday, 23 September 2015 at 13:14:54 UTC, Steven Schveighoffer
wrote:
You can do it in C++ via initializers too, just not as useful. D still
enforces sound construction.
The key quality for a good OO paradigm is that you can independently
modify super-classes and sub-classes in an encapsulated way without
knowing the concrete implementation of the other.
Any usage of virtual functions by the base class ctor is bound to be
something that is known by the derived class author. In fact, it's
likely to be a feature.
If the base ctor doesn't call any virtual functions, when it's
constructed doesn't really matter.
Like most languages C++ and D does not ensure sound object construction,
but C++ is a bit better than D. When you allow super() to be called in
arbitrary locations then modifications of ancestor classes are much more
likely to cause issues for subclasses. So that approach does not scale.
I don't see how you come to that conclusion. The derived class must
control construction of the base class. All D does is allow you to write
code that can build the parameters for the base class to use for
construction, instead of forcing you to write it in one expression like C++.
It requires slightly more careful thought (and some rules from the
compiler), but it scales just fine. We don't have to be purists for a
paradigm to reap the benefits.
-Steve