Sealed classes and methods: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Changed to Wren S/H)
m (Fixed typo.)
Line 4: Line 4:
In [[wp:Object-oriented_programming|object-oriented programming]], a '''sealed''' or '''final class''' is one which cannot be inherited from.
In [[wp:Object-oriented_programming|object-oriented programming]], a '''sealed''' or '''final class''' is one which cannot be inherited from.


Classes are sometimes made non-subclasssable in this way if the author feels that it would not be useful or even undesirable for subclasses to be created from them. Moreover, in a compiled language, knowing that a class cannot be subclassed, may enable optimizations to be made.
Classes are sometimes made non-subclassable in this way if the author feels that it would not be useful or even undesirable for subclasses to be created from them. Moreover, in a compiled language, knowing that a class cannot be subclassed, may enable optimizations to be made.


Rather than sealing the entire class, it may be possible to just seal certain methods for the same reasons and with the same potential benefits.
Rather than sealing the entire class, it may be possible to just seal certain methods for the same reasons and with the same potential benefits.