liveBook · Manning

Inheritance

As explained in Clojure: The Essential Reference

Concrete inheritance is an object-oriented mechanism in which a concrete class inherits implementation from another concrete class.

Concrete inheritance lets one concrete class reuse implementation from another. Clojure rejects concrete inheritance in its object-oriented model, while retaining Java interoperation for extending classes and working with existing types. section 15.0

Clojure separates class extension from its preferred polymorphism mechanisms:

  • gen-class can generate Java classes that implement interfaces and extend existing classes. section 15.0
  • proxy can extend classes and override protected methods, whereas reify is limited to implementing interfaces. section 15.0
  • defrecord is built on deftype and offers some form of inheritance, while defprotocol establishes dynamic dispatch independently from Java. section 15.0 section 11.1.4

Record-based alternative

A record creates a named object with fields and map-like access: `(defrecord abc [a b c])` followed by `(abc. 1 2 3)` produces `#user.abc{:a 1, :b 2, :c 3}`. This illustrates Clojure's structured-type approach rather than a concrete subclass declaration. section 11.1.4

How Clojure: The Essential Reference covers it

How deep it goes
Contrasts Clojure's prohibition with Java-oriented extension points but stops short of inheritance mechanics or dispatch internals.
Examples
Uses gen-class, proxy, reify, deftype, defrecord, and defprotocol as contrasting type and polymorphism mechanisms.
What you can do after
Evaluate whether Java class extension, records, or protocol-based dispatch fits a Clojure design.
How it connects
Connects inheritance with Java classes, interfaces, polymorphism, gen-class, proxy, deftype, defrecord, and defprotocol.

Also explained in

Compare how 19 books explain inheritance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.