Large software systems are assembled from smaller parts. In object-oriented design, parts are connected through two main mechanisms: composition and inheritance. Composition means that one object holds a reference to another object and delegates some functionality to it. Although this sounds straightforward, unprincipled composition can lead to a mess of spaghetti code. In this chapter I give a quick refresher on the mechanism of polymorphism and how it can be used to elegantly compose objects together by following some well-known design patterns. The second way of assembling systems is through inheritance, which is more complex and is covered in Chapter 7.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Composition

  • Martin P. Robillard

摘要

Large software systems are assembled from smaller parts. In object-oriented design, parts are connected through two main mechanisms: composition and inheritance. Composition means that one object holds a reference to another object and delegates some functionality to it. Although this sounds straightforward, unprincipled composition can lead to a mess of spaghetti code. In this chapter I give a quick refresher on the mechanism of polymorphism and how it can be used to elegantly compose objects together by following some well-known design patterns. The second way of assembling systems is through inheritance, which is more complex and is covered in Chapter 7.