What is "binding" and what makes it late?

“Late binding” is one of those computer-sciency terms that, like “strong typing”, means different things to different people. I thought I might describe what the term means to me. First off, what is “binding”? We can’t understand what it means to bind late if we don’t know what it is to bind at all. A…


Implementing the virtual method pattern in C#, Part Three

(This is part three of a three-part series; part one is here; part two is here.) Last time we saw how you could emulate virtual methods in a language that only had static methods by creating fields of delegate type, and then choosing what delegates go into the fields. However, this is not very space-efficient….


Implementing the virtual method pattern in C#, Part Two

(This is part two of a three-part series; part one is here; part three is here.) So far we’ve gotten rid of instance methods; they’re just static methods that take a hidden “this” parameter. But virtual methods are a bit harder. We’re going to implement virtual methods as fields of delegate type containing delegates to…


Implementing the virtual method pattern in C#, Part One

(This is part one of a three-part series; part two is here.) If you’ve been in this business for any length of time you’ve undoubtedly seen some of the vast literature on “design patterns” — you know, those standard solutions to common problems with names like “factory” and “observer” and “singleton” and “iterator” and “composite”…


Strange, but legal

“Can a property or method really be marked as both abstract and override?” one of my coworkers just asked me. My initial gut response was “of course not!” but as it turns out, the Roslyn codebase itself has a property getter marked as both abstract and override. (Which is why they were asking in the…


All your base do not belong to you

People sometimes ask me why you can’t do this in C#: class GrandBase{  public virtual void M() { Console.WriteLine(“GB”); }}class Base : GrandBase{  public override void M() { Console.WriteLine(“B”); }}class Derived : Base{  public override void M()   {     Console.WriteLine(“D”);    base.base.M(); // illegal!   }} The author of the most-derived class here wishes to…


Putting a base in the middle

Here’s a crazy-seeming but honest-to-goodness real customer scenario that got reported to me recently. There are three DLLs involved, Alpha.DLL, Bravo.DLL and Charlie.DLL. The classes in each are: public class Alpha // In Alpha.DLL{  public virtual void M()  {    Console.WriteLine(“Alpha”);  }} public class Bravo: Alpha // In Bravo.DLL{} public class Charlie : Bravo // In…


Double Your Dispatch, Double Your Fun

Here’s an interesting question I got the other day: If you have an overloaded operator == then any call to the operator method is “early bound” at compile time according to the compile-time types of the operands. But calling Equals() on an object is a virtual call; the actual method called is bound at runtime according…


Virtual Methods and Brittle Base Classes

Hey, I’m back! And in my new location. That was the longest and least relaxing vacation I’ve ever taken. Fun, yes. Relaxing, no. And to top it off, my kitchen is not done yet. We’re shooting for being able to run water tonight and actually use appliances by tomorrow night, but we’ll see how it…