12.07.2015 Views

Is Python a

Is Python a

Is Python a

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 26CHAPTER 26Advanced Class Topics26This chapter concludes Part VI and our look at OOP in <strong>Python</strong> by presenting a fewmore advanced class-related topics: we will survey subclassing built-in types,pseudoprivate attributes, new-style classes, static methods, function decorators, andmore.As we’ve seen, <strong>Python</strong>’s OOP model is, at its core, very simple, and some of thetopics presented in this chapter are so advanced and optional that you may notencounter them very often in your <strong>Python</strong> applications-programming career. In theinterest of completeness, though, we’ll round out our discussion of classes with abrief look at these advanced tools for advanced OOP work.As usual, because this is the last chapter in this part of the book, it ends with a sectionon class-related gotchas, and the set of lab exercises for this part. I encourageyou to work through the exercises to help cement the ideas we’ve studied here. I alsosuggest working on or studying larger OOP <strong>Python</strong> projects as a supplement to thisbook. As with much in computing, the benefits of OOP tend to become more apparentwith practice.Extending Built-in TypesBesides implementing new kinds of objects, classes are sometimes used to extend thefunctionality of <strong>Python</strong>’s built-in types to support more exotic data structures. Forinstance, to add queue insert and delete methods to lists, you can code classes thatwrap (embed) a list object, and export insert and delete methods that process the listspecially, like the delegation technique studied in Chapter 25. As of <strong>Python</strong> 2.2, youcan also use inheritance to specialize built-in types. The next two sections show bothtechniques in action.539

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

Saved successfully!

Ooh no, something went wrong!