Hacker News new | ask | show | jobs
by hota_mazi 3094 days ago
These concepts are orthogonal.

I can use composition and inheritance to define an IS_A relationship and I can use them to define a HAS_A relationship.

For example, in Kotlin:

    class A : B // IS_A via inheritance    
    class A(b: B) {  // HAS_A via composition
    class A(b: B) : B by b // IS_A via composition
1 comments

> class A(b: B) : B by b // IS_A via composition

I couldn't find the "B by b" syntax from the Kotlin docs, can you tell me that this does ?

It's delegation.

Look at page 96 of this PDF file: https://kotlinlang.org/docs/kotlin-docs.pdf

Thank you, wish Java had this :'(