In Scala, collections such as Vector are sealed to prevent inheritance, which is crucial for maintaining safety and performance. This design choice encapsulates internal implementations, ensuring that changes do not inadvertently affect subclasses. Inheriting from collections could lead to the Fragile Base Class problem, where future updates to the base class may break existing subclasses. Scala promotes composition over inheritance, encouraging developers to use existing collections by delegating functionalities instead of extending them.
One of the main reasons for prohibiting inheritance in Scala collections is to maintain encapsulation of their internal implementations, ensuring optimal performance and predictable behavior.
Allowing direct inheritance from types like Vector could expose internal details, leading to unwanted behavior. This breaks the safety guarantees designed into the Scala collections.
Collection
[
|
...
]