You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please consider adding the following language feature:
abstract class Base
{
public static abstract string Something { get; }
}
class Derived1 : Base
{
public static string Something => "Derived";
}
class Derived2 : Base { } // Compiler error.
Base.Something // Compiler error.
Derived.Something // OK.
void Something<T>() where T : Base { T.Something; // OK. }
A common pattern is to use Flyweight in this fashion:
class FlyweightFactory
{
Dictionary<KeyType, Flyweight> _flyweights;
public GetFlyweight(KeyType key) => _flyweights[key];
}
When it comes to populating the dictionary, in many cases the flyweight concrete classes have a unique key corresponding to their types. If we want to enforce the presence of the key on the sub types, we can define an abstract property/method on the base flyweight; but this means we have to create an instance only to get a constant value. On the other hand, we could use attributes (which are more fit for purpose), but there is no way to enforce an attribute.
The abstract static would solve this problem.
Or, as an alternative, an abstract attribute which must be overridden by the sub types.
The text was updated successfully, but these errors were encountered:
Please consider adding the following language feature:
A common pattern is to use Flyweight in this fashion:
When it comes to populating the dictionary, in many cases the flyweight concrete classes have a unique key corresponding to their types. If we want to enforce the presence of the key on the sub types, we can define an abstract property/method on the base flyweight; but this means we have to create an instance only to get a constant value. On the other hand, we could use attributes (which are more fit for purpose), but there is no way to enforce an attribute.
The abstract static would solve this problem.
Or, as an alternative, an abstract attribute which must be overridden by the sub types.
The text was updated successfully, but these errors were encountered: