Why should you prevent a class from being subclassed?

oop

Solution

Because writing classes to be substitutably extended is damn hard and requires you to make accurate predictions of how future users will want to extend what you've written.

Sealing your class forces them to use composition, which is much more robust.

Problem

What can be reasons to prevent a class from being inherited? (e.g. using sealed on a c# class) Right now I can't think of any.

Original source