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

Is it possible to assign a base class object to a derived class reference with an explicit typecast?

No. A reference to a derived class must actually refer to an instance of the derived class (or null). Otherwise how would you expect it to behave? For example: object o = new object(); string s = (string) o; int i = s.Length; // What can this sensibly do? If you want to be able … Read more

C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass

There are examples in the Framework with the Base suffix, e.g. System.Configuration.Provider.ProviderBase, System.Web.SessionState.SessionStateStoreProviderBase. But by no means all abstract base classes in the Framework follow this convention (e.g. System.Data.Common.DbParameter, System.Data.Common.DbCommand). Personally I would avoid using the suffix unless I wanted to emphasize the fact that it’s an abstract class and felt that otherwise users of … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)