7

I know this is "technically" a duplicate of this question. Should I recommend sealing classes by default?

But I'm asking it again because apparently the recommendation has changed1 with the times though I can't find anything in the last few years about it or about the fact that more and more people are recommending AGAINST sealing classes now thanks to the improvements in testing (which was one of the main reasons), processor speed (speed difference now is negligible), etc.

I'm trying to find out what the latest guideline is for weather or not to mark classes as sealed.

1 Essential C# 6.0 (5th Edition), Mark Michaelis (co author Eric Lippert):

"In general, marking a class as sealed is rarely done and should be reserved only for those situations in which there are strong reasons favoring such a restriction. In fact, leaving types unsealed is increasingly desirable, as unit testing has become prominent because of the need to support mock (test double) object creation in place of real implementations."

This is hardcopy proof as the others are all word of mouth.

Community
  • 1
  • 1
Storm
  • 1,848
  • 4
  • 20
  • 39
  • Also, there is no proof of your "apparently the recommendation has changed", which invalidates your argument for a new question. – Patrick Hofman Jan 16 '16 at 13:25
  • Classes should be open for extension, but closed for modification. You can't explicitly do both in C#, but to enable extension they need to remain unsealed. – Enigmativity Jan 16 '16 at 13:25
  • @PatrickHofman "Proof" added as requested – Storm Jan 16 '16 at 13:33
  • 9
    Mark and I disagree slightly on the merits of sealing classes by default. I am still much more inclined to say "seal it, and then unseal it if you find it convenient to do so". I agree with Mark that it is rarely done. However I did not feel strongly enough about it to argue that the text should be changed. – Eric Lippert Jan 16 '16 at 14:49
  • @EricLippert Thank you Eric for that valuable insight, it is highly appreciated as always. – Storm Jan 17 '16 at 09:10

0 Answers0