Chapter 20. Advanced object-oriented features

 

This chapter covers

  • Using special method attributes
  • Making an object behave like a list
  • Subclassing built-in types
  • Understanding metaclasses
  • Creating abstract base classes

This chapter will focus on some more advanced object-oriented features of Python. Python is distinguished by the ability to modify its objects in ways that can fundamentally change their behavior. For C++ users, this is somewhat similar to operator overloading, but in Python it’s more comprehensive and easier to use.

In addition to modifying the behavior of objects, you can also control the behavior of classes and the creation of their instances. Obviously, you’ll need to be fairly familiar with OO programming to use this feature.

20.1. What is a special method attribute?

A special method attribute is an attribute of a Python class with a special meaning to Python. It’s defined as a method but isn’t intended to be used directly as such. Special methods aren’t usually directly invoked; instead, they’re called automatically by Python in response to a demand made on an object of that class.

20.2. Making an object behave like a list

20.3. Giving an object full list capability

20.4. Subclassing from built-in types

20.5. When to use special method attributes

20.6. Metaclasses

20.7. Abstract base classes

20.8. Summary

sitemap