Software Design/Prohibit overriding implementation of a function
Why
edit- Harder to reason about the behavior of a class if the function might be overridden in a subclass.
- Fosters scattering the logic across the hierarchy => more navigation is required, easier to make mistakes because the logic of a procedure is not at the same place in front of the developer's eyes.
Why not
edit- Forces to write boilerplate code (and leads to increased code size) when inheriting behavior from abstract classes (e. g. Java's default methods).
- May lead to some logic duplication between implementations of a function in different classes extending an abstract class: see practice Don't repeat logic in several places.
Related
editSources
edit- A De Goes, John (October 26, 2019). "12 Steps to Better Scala". Hamburg, Germany: Scala Hamburg. "Make Methods Final or Abstract"