When to use composition vs inheritance

In Java 101: Inheritance in Java, Part 1, you learned how to leverage inheritance for code reuse, by establishing is-a relationships between classes. Composition is 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 one class from another class. The distinction is subtle at first, but it will make more sense once you see it in code.

To read this article in full, please click here

(Insider Story)

分類: IT 資訊科技(信息技术), java教學網站, 熱門新聞, 科技趣聞,標籤: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 。這篇內容的永久連結