Unit 5. State and behavior
In Go, values represent state, such as whether a door is opened or closed. Functions and methods define behavior—actions on state, such as opening a door.
As programs grow larger, they become more difficult to manage and maintain, unless you have the right tools.
If there are several doors that can independently be opened or closed, it’s helpful to bundle the state and behavior together. Programming languages also allow you to express abstract ideas, such as things that can be opened. Then on a hot summer day, you can open everything that can be opened, whether door or window.
There are a lot of big words to describe these ideas: object-orientation, encapsulation, polymorphism, and composition. The lessons in this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access