0

Should I declare all classes that aren't inherited as final even if they don't have anything to do with inheritance and that kind of stuff?

  • 7
    This is essentially a question of style; valid opinions range over the entire scope of possibilities between "`final` should only be used when there is a concrete reason why subclassing a particular class would *in and of itself* be a bug" and "`final` should *always* be used, except when there is either an immediate need for a subclass, or an obvious reason why someone might want to subclass this class in the future". – zwol Dec 07 '13 at 17:44
  • 1
    `final` should probably *never* be used. I have yet to see a use case for it. Related: http://stackoverflow.com/questions/16808184 – Casey Dec 07 '13 at 17:57

1 Answers1

2

A class should be declared final when you want to declare the statement "this class cannot be inherited". This is not the same case as the statement "this class is not inherited". It is a matter of opinion but I would not forbid the inheritance of a class, unless there is a very specific reason to do so. Therefore, I would not declare a class final unless there was a reason to do so.

Hope I helped!

Pantelis Natsiavas
  • 5,293
  • 5
  • 21
  • 36