Lesson 23. Composition and forwarding

After reading lesson 23, you’ll be able to

  • Compose structures with composition
  • Forward methods to other methods
  • Forget about classical inheritance

When you look around the world, everything you see is made up of smaller parts. People tend to have bodies with limbs, which in turn have fingers or toes. Flowers have petals and stems. Mars Rovers have wheels and treads and entire subsystems, like the Rover Environmental Monitoring Station (REMS). Each part plays its role.

In the world of object-oriented programming, objects are composed of smaller objects in the same way. Computer scientists call this object composition or simply composition.

Gophers use composition with structures, and Go provides a special ...

Get Get Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.