O'Reilly logo

Get Programming with Go by Nathan Youngman and Roger Peppé

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required