If you are sure you need to extend some functionality of string, then extension methods are a good option for the
string
class.
Inheritance is often abused, especially in C++ which doesn't have a concept of sealed. If you are developing a class
X
, be very sure that it
X is a string, rather than
X is implemented in terms of string. The tight coupling of client code of X to string can cause problems down the road. The sealed keyword is actually a safeguard against this. More often than not it is a useful protection from deriving business classes from lower level classes. Business classes are almost always
implemented in terms of lower level classes.
I'll be honest and say this is something that was only recently pointed out to me in the context of C++ development, but I would say the same applies to most languages. Inheritence is one of the most strongest relationship between classes that one can form as pointed out be Herb Sutter:
Uses and Abuses of Inheritance[
^]. Again, C++ references, but probably relevant to this question.