Objects in Action

Consider the case of the program that displays a pie chart. A PieChart object could consist of the following:

• Behavior to calculate the size of each pie slice

• Behavior to draw the chart

• An attribute to store the title of the chart

It might seem odd to ask the PieChart object to draw itself because graphs don’t draw themselves in the real world. Objects in OOP work for themselves whenever possible. This quality makes it easier to incorporate them in other programs. If a PieChart object did not know how to draw itself, for instance, every time you used that PieChart object in another program, you would have to create behavior to draw it.

Note

An autodialer is software that uses a modem to dial a series of phone numbers ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition 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.