What is the point of using abstract methods?

Say you have three printers that you need to write drivers for, Lexmark, Canon, and HP. All three printers will have the print() and getSystemResource() methods. However, print() will be different for each printer, and getSystemResource() remains the same for all three printers. You also have another concern, you would like to apply polymorphism. Since …

Read more

Abstract UserControl inheritance in Visual Studio designer

What we want First, let’s define the final class and the base abstract class. public class MyControl : AbstractControl … public abstract class AbstractControl : UserControl // Also works for Form … Now all we need is a Description provider. public class AbstractControlDescriptionProvider<TAbstract, TBase> : TypeDescriptionProvider { public AbstractControlDescriptionProvider() : base(TypeDescriptor.GetProvider(typeof(TAbstract))) { } public override …

Read more

How can I assure a class to have a static property by using interface or abstract?

You can’t do that. Interfaces, abstract, etc. cannot apply to static members. If you want to accomplish this, you will have to manually remember to do it on all deriving classes. Also, static members are inherited by deriving classes. Child classes must hide the static parent member if they wish to specify alternate behavior.

Determine if a Python class is an Abstract Base Class or Concrete

import inspect print(inspect.isabstract(object)) # False print(inspect.isabstract(MessageDisplay)) # True print(inspect.isabstract(FriendlyMessageDisplay)) # True print(inspect.isabstract(FriendlyMessagePrinter)) # False This checks that the internal flag TPFLAGS_IS_ABSTRACT is set in the class object, so it can’t be fooled as easily as your implementation: class Fake: __abstractmethods__ = ‘bluh’ print(is_abstract(Fake), inspect.isabstract(Fake)) # True, False