Back to Comprehensive Rust

From OOP to Rust: Composition, Not Inheritance

src/idiomatic/polymorphism/from-oop-to-rust.md

latest848 B
Original Source
<!-- Copyright 2025 Google LLC SPDX-License-Identifier: CC-BY-4.0 -->

From OOP to Rust: Composition, Not Inheritance

  • Inheritance is key to OOP's success as a paradigm. Decades of successful software engineering has been done with Inheritance as a core part of business logic.

  • So why did Rust avoid inheritance?

  • How do we move from inheritance-based problem solving to Rust's approach?

  • How do you represent heterogeneous collections in Rust?

<details>
  • In this section we'll be looking at how to move from thinking about polymorphic problem solving with types in OOP languages like java, C++ etc. to Rust's trait-based approach to Polymorphism.

  • There will be differences, but there are also plenty of areas in common – especially with modern standards of OOP development. Remember to keep an open mind.

</details>