Objects in Action
Consider the case of a program that displays a pie chart. A PieChart object could consist of the following:
Behavior to calculate how big each pie slice should be in the chart
Behavior to draw the chart
An attribute to store the title of the chart
When you compare a pie chart in the real world to a PieChart object in a computer program, it might seem odd to ask the PieChart object to draw itself. Graphs don't draw themselves in the real world. However, objects in object-oriented programming work for themselves whenever possible. This quality makes them more useful because you can incorporate them in other programs without having as many things to teach them. If a PieChart object did not know how to draw itself, for instance, every ...
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