Abstract property with public getter, define private setter in concrete class possible?

Unfortunately, you can’t do exactly what you want. You can do this with interfaces though: public interface IInterface { string MyProperty { get; } } public class Class : IInterface { public string MyProperty { get; set; } } The way I would do it is to have a separate SetProperty method in the concrete … Read more

Difference between Trait and an Abstract Class in PHP

Traits allow you to share code between your classes without forcing you into a specific class hierarchy. Say you want all your classes to have the convenient utility method foo($bar); without traits you have two choices: implement it individually with code redundancy in each class inherit from a common (abstract) ancestor class Both solution aren’t … Read more

Is there a way to make a method which is not abstract but must be overridden?

There is no direct compiler-enforced way to do this, as far as I know. You could work around it by not making the parent class instantiable, but instead providing a factory method that creates an instance of some (possible private) subclass that has the default implementation: public abstract class Base { public static Base create() … Read more

Error: “Cannot use ‘async’ on methods without bodies”. How to force async child overrides?

Whether a method is implemented using async/await or not is an implementation detail. How the method should behave is a contract detail, which should be specified in the normal way. Note that if you make the method return a Task or a Task<T>, it’s more obvious that it’s meant to be asynchronous, and will probably … Read more

python subclasscheck & subclasshook

Both methods can be used to customize the result of the issubclass() built-in function. __subclasscheck__ class.__subclasscheck__(self, subclass) Return true if subclass should be considered a (direct or indirect) subclass of class. If defined, called to implement issubclass(subclass, class). Note that these methods are looked up on the type (metaclass) of a class. They cannot be … Read more

Why can’t I create an abstract constructor on an abstract C# class?

You cannot have an abstract constructor because abstract means you must override it in any non-abstract child class and you cannot override a constructor. If you think about it, this makes sense, since you always call the constructor of the child class (with the new operator) and never the base class. Generally speaking, the only … Read more