Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
We did major surgery to Shapes-Object, taking all that code out of Circle and Rectangle and moving it into Shape. It's very cool that the rest of the program still works, without modification. Creating and initializing all the different shapes in main() didn't change, and the drawShapes() function is the same, yet the program still works:
drawing a circle at (0 0 10 30) in reddrawing a rect at (30 40 50 60) in greendrawing an egg at (15 19 37 29) in bluedrawing a triangle at (47 32 80 50) in redHere, you can see another aspect of the power of OOP: you can make radical changes to a program, and if you're careful, things will still work when you're done. Of course, you can do that with procedural programming, but your chances of success are usually higher with OOP.