First, I believe that the world of shrink-wrapped proprietary software should die.
Second, I fail to see how inheritance solves your problem: "The code using LibType is code you don't control; you can't change it to use MyType instead."
OK, let's try this with inheritance.
class LibType { Handles 3 cases }
class MyType extends LibType { Handles a fourth case }
Now tell me: how would you make the code of the library use an object of type `MyType` instead of `LibType`? If you don't control its code, I see only one way: somewhere, this library expects an object of type `LibType` as a
parameter.
Interestingly, idiomatic functional programming do just that: passing functions as parameters. Or tuples of functions, in that case. You know that an object is just a tuple, right?. For instance:
// Statically typed, Class based OO language
class Foo {
int bar(int,);
float baz(float, int);
int x;
}
-- Haskell
data Foo = Foo (Int -> Int)
(Float -> Int -> Int)
Int
-- The same, with record syntax. (for easy access)
data Foo = Foo { bar :: Int -> Int
baz :: Float -> Int -> Int
x :: Int
}
Note that the functions in objects of type Foo aren't fixed. So I can override all I want. Class Polymorphism is cool, but I can do the same with mere parametric polymorphism if I really need to. Sure, the library must be designed for extensibility in the first place, but the same is true about OO libraries: inheriting from a class that isn't designed with inheritance in mind is dangerous.