Skip to main content

Object Orientation

  • Chapter
  • First Online:
Lean Python
  • 10k Accesses

Abstract

The professional approach to programming has shifted away from designing systems with a hierarchy of features defined in functions toward an object-oriented (OO) approach. We look here at how Python fully supports object orientation.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 24.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 34.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Object orientation is a big topic. You can see an overview of OO programming at http://en.wikipedia.org/wiki/Object-oriented_programming .

  2. 2.

    When you create a new object from a class definition, that object is sometimes called an instance and the create process called instantiation. We use the word object, though, in our description.

  3. 3.

    It is a design choice as to whether we hide attributes and make them available only through methods (private attributes) or expose them to the outside world (public).

  4. 4.

    Note that the first argument to all of the methods in the class is 'self', the object itself. This argument is used internally in the class and is not exposed to the code that calls these methods, as you'll see in the test that follows. The "self." attributes are public.

  5. 5.

    The Python implementation of OO differs in some respects from other languages such as Java, for example. Python has a rather more “relaxed” attitude to OO, which makes some things easier for the programmer, but does mean that the programmer needs to be a little more careful in his or her coding. It is up to you to decide which approach is best.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Paul Gerrard

About this chapter

Cite this chapter

Gerrard, P. (2016). Object Orientation. In: Lean Python. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-2385-7_6

Download citation

Publish with us

Policies and ethics