Object-Oriented Programming Features

Oxide is fundamentally a systems programming language rooted in the functional and type-system capabilities of Rust. However, Oxide incorporates many object-oriented programming (OOP) features that allow you to write code in a style familiar to those coming from traditional OOP languages. This chapter explores how Oxide supports OOP patterns while maintaining its emphasis on safety and performance.

What Is OOP?

Object-oriented programming is a programming paradigm organized around objects that contain data and behavior. When we talk about OOP in Oxide, we're discussing design patterns and language features that enable this style of programming. Some argue whether Oxide truly qualifies as an OOP language, but it provides the tools you need to structure your programs using OOP principles.

Rust, and by extension Oxide, takes a different approach than some traditional OOP languages. Rather than inheriting implementations from parent classes, Oxide uses trait composition and extension blocks to achieve similar goals with better safety guarantees and more explicit control.

Topics Covered

This chapter covers three core OOP concepts as they apply to Oxide:

  1. Encapsulation - Bundling data with the methods that operate on it, while controlling which details are exposed to the outside world.

  2. Inheritance vs. Composition - Understanding how Oxide achieves code reuse through trait composition rather than class inheritance, and how to design flexible, maintainable abstractions.

  3. Trait Objects - Using dynamic dispatch with dyn Trait to work with multiple types through a common interface at runtime.

These features work together to enable you to build scalable, maintainable systems in Oxide.

The Oxide Approach to OOP

Rather than traditional class inheritance hierarchies, Oxide emphasizes:

  • Traits for defining behavior contracts
  • Extension blocks for adding methods to types
  • Composition for building complex types from simpler ones
  • Type safety enforced at compile time

This approach reduces common OOP pitfalls like fragile base class problems and provides more predictable behavior.

Let's begin by exploring how Oxide achieves encapsulation.