Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Fragile base class
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Solutions== * [[Objective-C]] has [[Objective-C#Categories|categories]] as well as [[Objective-C#Non-fragile instance variables|non-fragile instance variables]]. * [[Component Pascal]] deprecates [[Superclass (computer science)|superclass calls]]. * [[Java (programming language)|Java]], [[C++]] (Since C++11) and [[D (programming language)|D]] allow inheritance or overriding a class method to be prohibited by labeling a declaration of a class or method, respectively, with the keyword "<code>final</code>". In the book ''Effective Java'', author [[Joshua Bloch]] writes (in item 17) that programmers should "Design and document for inheritance or else prohibit it". * [[C Sharp (programming language)|C#]] and [[VB.NET]] like Java have "<code>sealed</code>" and "<code>Not Inheritable</code>" class declaration keywords to prohibit inheritance, and require a subclass to use keyword "<code>override</code>" on overriding methods,<ref>{{Cite web | url=https://msdn.microsoft.com/en-us/library/ebca9ah3.aspx | title=Override modifier - C# Reference }}</ref> the same solution later adopted by Scala. * [[Scala (programming language)|Scala]] require a subclass to use keyword "<code>override</code>" explicitly in order to override a parent class method. In the book "Programming in Scala, 2nd Edition", the author writes that (with modifications here) If there was no method f(), the client’s original implementation of method f() could not have had an override modifier. Once you add the f() method to the second version of your library class, a recompile of the client code would give an compile error instead of wrong behavior. * In [[Kotlin (programming language)|Kotlin]] classes and methods are final by default. To enable the class inheritance, the class should be marked with the <code>open</code> modifier. Likewise, a method should be marked as <code>open</code> to allow overriding of the method. * [[Julia (programming language)|Julia]] allows only subtyping of abstract types and uses composition as an alternative to [[Inheritance (object-oriented programming)|inheritance]]. It however has [[multiple dispatch]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)