logoalt Hacker News

zwieback01/22/20252 repliesview on HN

If I remember correctly, Liskov didn't talk about inheritance but subtyping in a more general way. Java, C++ and other, especially statically typed, compiled languages often use inheritance to model subtyping but Liskov/Wing weren't making any statements about inheritance specifically.


Replies

cratermoon01/22/2025

>subtyping in a more general way

This is correct. I read her paper closely. One example I give is how SICP provides two implementations for complex numbers[1], the rectangular for and polar form.

    (make-rectangular (real-part z) (imag-part z))
and

    (make-polar (magnitude z) (angle z))
then on page 138 provides this interface that both satisfy

    (define (real-part obj) (operate 'real-part obj))
        (define (imag-part obj) (operate 'imag-part obj))
        (define (magnitude obj) (operate 'magnitude obj))
        (define (angle obj) (operate 'angle obj))


1 https://mitp-content-server.mit.edu/books/content/sectbyfn/b...
rramadass01/22/2025

> use inheritance to model subtyping but Liskov/Wing weren't making any statements about inheritance specifically.

Right. Inheritance is just one mechanism to realize Subtyping. When done with proper contract guarantees (i.e. pre/post/inv clauses) it is a very powerful way to express semantic relationships through code reuse.