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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 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.
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.
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.
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.
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
Rights 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
DOI: https://doi.org/10.1007/978-1-4842-2385-7_6
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-2384-0
Online ISBN: 978-1-4842-2385-7
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)