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

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