12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Why You Will Care: OOP by the MastersWhen I teach <strong>Python</strong> classes, I invariably find that about halfway through the class,people who have used OOP in the past are following along intensely, while people whohave not are beginning to glaze over (or nod off completely). The point behind thetechnology just isn’t apparent.In a book like this, I have the luxury of including material like the new Big Picture overviewin Chapter 22—in fact, you should probably review that section if you’re startingto feel like OOP is just some computer science mumbo-jumbo.In real classes, however, to help get the newcomers on board (and keep them awake),I have been known to stop and ask the experts in the audience why they use OOP. Theanswers they’ve given might help shed some light on the purpose of OOP, if you arenew to the subject.Here, then, with only a few embellishments, are the most common reasons to useOOP, as cited by my students over the years:Code reuseThis one’s easy (and is the main reason for using OOP). By supporting inheritance,classes allow you to program by customization, instead of starting eachproject from scratch.EncapsulationWrapping up implementation details behind object interfaces insulates users of aclass from code changes.StructureClasses provide new local scopes, which minimizes name clashes. They also providea natural place to write and look for implementation code, and to manageobject state.MaintenanceClasses naturally promote code factoring, which allows us to minimize redundancy.Thanks both to the structure and code reuse support of classes, usuallyonly one copy of the code needs to be changed.ConsistencyClasses and inheritance allow you to implement common interfaces, and hence, acommon look and feel in your code; this eases debugging, comprehension, andmaintenance.PolymorphismThis is more a property of OOP than a reason for using it, but by supporting codegenerality, polymorphism makes code more flexible and widely applicable, andhence, more reusable.—continued—Part VI Exercises | 571

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!