inheritance
Method Overriding and Optional Parameters
Okay, as there’s general interest, here’s a quick version: Console.WriteLine(one) This will use the WriteLine(object) overload, which will in turn execute the object.ToString() virtual method, overridden in One – hence the output of ToString override Console.WriteLine(one.ToString()) This will look at One and see which methods have newly declared methods – discounting overrides. There’s exactly one … Read more
Swift protocol extension method is called instead of method implemented in subclass
This is just how protocols currently dispatch methods. A protocol witness table (see this WWDC talk for more info) is used in order to dynamically dispatch to implementations of protocol requirements upon being called on a protocol-typed instance. All it is, is really just a listing of the function implementations to call for each requirement … Read more
Using “Base” in a Class Name
I tend to add a Base suffix to the name of the base class only if it exists from technical perspective (to share some code), and doesn’t really constitute any usable class on its own (so all of these classes are abstract). These are quite rare cases though, and should be avoided just as Helper … Read more
How can a derived class invoke private method of base class?
Because you defined the main method in PrivateOverride class. If you put the main method in Derived class, it would not compile, because .f() would not be visible there. po.f() call in PrivateOverride class is not a polymorphism, because the f() in PrivateOverride class is private, so f() in Derived class is not overriden.
Assignment operator not available in derived class
Every class has at least one assignment operator implicitly defined when we don’t provide one ourselves. And when a member function in a derived class is defined with the same name as a member in the base class, it hides all the base class definitions for that name. You can use a using declaration, but … Read more
Hibernate @Embeddable class which extends another @Embeddable class, Properties not found for @OneToMany mapping
You can implement inheritance between @Embeddable classes. You just have to annotate the parent class with @MappedSuperclass too. So, e.g.: @Embeddable @MappedSuperclass public class Parent { @Basic private String parentProperty; // … getters/setters } @Embeddable public class Child extends Parent { @Basic private String childProperty; // … getters/setters } This way Hibernate (tested with 5.x) … Read more
Design advice – When to use “virtual” and “sealed” effectively [closed]
Start with the Microsoft Design Guidelines for Developing Class Libraries, particularly the Extensibility section, where you’ll find articles on virtual members and sealing. Quoting, here: Do not make members virtual unless you have a good reason to do so and you are aware of all the costs related to designing, testing, and maintaining virtual members. … Read more
Get child constant in parent method – Ruby
EDIT: this answer is correct, although Wayne’s is the more ruby-ish way to approach the problem. Yes it is. Your implementation will not work, because the parent tries to resolve EWOK locally. Parent doesn’t have EWOK defined. However, you can tell Ruby to look specifically at the class of the actual instance the method was … Read more
How can I prevent a base constructor from being called by an inheritor in C#?
There is a way to create an object without calling any instance constructors. Before you proceed, be very sure you want to do it this way. 99% of the time this is the wrong solution. This is how you do it: FormatterServices.GetUninitializedObject(typeof(MyClass)); Call it in place of the object’s constructor. It will create and return … Read more