Why collections classes in C# (like ArrayList) inherit from multiple interfaces if one of these interfaces inherits from the remaining?

OK, I’ve done some research. If you create the following hierarchy: public interface One { void DoIt(); } public interface Two : One { void DoItMore(); } public class Magic : Two { public void DoItMore() { throw new NotImplementedException(); } public void DoIt() { throw new NotImplementedException(); } } And compile it, then reference … Read more

C# – Object Composition – Removing Boilerplate Code

I have a single generic repository interface, which is implemented only once for a particular data storage. Here it is: public interface IRepository<T> where T : class { IQueryable<T> GetAll(); T Get(object id); void Save(T item); void Delete(T item); } I have implementations of it for EntityFramework, NHibernate, RavenDB storages. Also I have an in-memory … Read more

TypeScript: ‘super’ must be called before before accessing ‘this’ in the constructor of a derived class

Another solution I eventually came up with, in addition to the ones provided by @iberbeu and @Nypan, is to add and intermediary initProps() method right before the call to scream(): class Person { public firstName: string; constructor(firstName: string, props?: any) { this.firstName = firstName; this.initProps(props); this.scream(); } protected initProps(props: any): void { } protected scream(): … Read more

Setting up a foreign key to an abstract base class with Django

A generic relation seems to be the solution. But it will complicate things even further. It seems to me; your model structure is already more complex than necessary. I would simply merge all three Answer models into one. This way: Answer_Risk would work without modification. You can set resident to None (NULL) in case of … Read more

C# interface static method call with generics

Try an extension method instead: public interface IMyInterface { string GetClassName(); } public static class IMyInterfaceExtensions { public static void PrintClassName<T>( this T input ) where T : IMyInterface { Console.WriteLine(input.GetClassName()); } } This allows you to add static extension/utility method, but you still need an instance of your IMyInterface implementation. You can’t have interfaces … Read more

Static methods and designing for inheritance

Inheritance clearly means a knowledge of the base class. @staticmethod is ignorant of the class it is ‘attached’ to(hence they earlier-not now-a-days-called it ‘unbound;’ now technically @staticmethod is not a method at all; it is a function. But @classmethod is fully aware of the class it is attached to; it is technically not a function, … Read more

Getting all superclasses in Python 3

Use the __mro__ attribute: >>> class A: … pass … >>> class B: … pass … >>> class C(A, B): … pass … >>> C.__mro__ (<class ‘__main__.C’>, <class ‘__main__.A’>, <class ‘__main__.B’>, <class ‘object’>) This is a special attribute populated at class instantiation time: class.__mro__ This attribute is a tuple of classes that are considered when … Read more