Java 101 primer: Composition and inheritance

    617

    In “Java 101: Inheritance in Java, Part 1,” you learned how to leverage inheritance for code reuse, by establishing is-a relationships between classes. This free Java 101 primer focuses on composition, a closely related programming technique that is used to establish has-a relationships instead. Whereas inheritance extends the features of one class to another, composition allows us to compose a class from another class. The distinction may seem subtle, but it will make more sense once you see it in code.

    To read this article in full or to leave a comment, please click here

    (Insider Story)

    Powered by WPeMatico