Order of calling base class constructor from derived class initialization list

The order you refer in your question is not the “order of calling base constructor”. In fact, you can’t call a constructor. Constructors are not callable by the user. Only compiler can call constructors. What you can do is to specify initializers. In this case (constructor initializer list) you are specifying initializers for subobjects of … Read more

.NET: Unable to cast object to interface it implements

I hat the same problems with a library of mine providing “plugin”-functionality… I got it finally working… Here was my problem: I had one main assembly using plugins, one assembly with the plugin (Plugin.dll) AND (important) another assembly providing the plugin-functionality (Library.dll). The Plugin.dll referenced the main assembly (in order to be able to extend … Read more

How to hide an inherited property in a class without modifying the inherited class (base class)?

I smell a code smell here. It is my opinion that you should only inherit a base class if you’re implementing all of the functionality of that base class. What you’re doing doesn’t really represent object oriented principles properly. Thus, if you want to inherit from your base, you should be implementing Name, otherwise you’ve … Read more

Cast base class to derived class python (or more pythonic way of extending classes)

If you are just adding behavior, and not depending on additional instance values, you can assign to the object’s __class__: from math import pi class Circle(object): def __init__(self, radius): self.radius = radius def area(self): return pi * self.radius**2 class CirclePlus(Circle): def diameter(self): return self.radius*2 def circumference(self): return self.radius*2*pi c = Circle(10) print c.radius print c.area() … Read more

GCC issue: using a member of a base class that depends on a template argument

David Joyner had the history, here is the reason. The problem when compiling B<T> is that its base class A<T> is unknown from the compiler, being a template class, so no way for the compiler to know any members from the base class. Earlier versions did some inference by actually parsing the base template class, … Read more

What are good candidates for base controller class in ASP.NET MVC?

There are no good uses of a base controller class. Now hear me out. Asp.Net MVC, especially MVC 3 has tons of extensibility hooks that provide a more decoupled way to add functionality to all controllers. Since your controllers classes are very important and central to an application its really important to keep them light, … Read more

Creating a singleton in Python

Use a Metaclass I would recommend Method #2, but you’re better off using a metaclass than a base class. Here is a sample implementation: class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] class Logger(object): __metaclass__ = Singleton Or in Python3 class Logger(metaclass=Singleton): … Read more