Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-x5gtn Total loading time: 0 Render date: 2024-05-01T00:21:30.226Z Has data issue: false hasContentIssue false

7 - Object orientation

Published online by Cambridge University Press:  05 February 2015

Tim J. Stevens
Affiliation:
MRC Laboratory of Molecular Biology, Cambridge
Wayne Boucher
Affiliation:
University of Cambridge
Get access

Summary

Creating classes

For simple tasks involving short programs, you can survive perfectly well with the standard Python data types for holding information, such as lists and dictionaries. However, for more complicated tasks involving long programs, this often becomes unwieldy. There are various ways to deal with this issue, but one of the most fruitful is the ability to define your own data types: objects built to your own specification, organised in the way that is convenient to you. Modern computer languages do this via the introduction of bespoke object definitions that are known as classes and this kind of thinking is generally termed object-oriented programming.

When creating your own custom data types, the class is the definition of a particular kind of object in terms of its component features and how it is constructed or implemented in code. The term object, however, refers to a specific instance, or occurrence, of the thing which has been made according to the class definition. The making of an object of a given class is what is usually termed instantiation. A convenient analogy is to think of the blueprint for a house being like a class, but the actual, solid house being the object. Also, given a single blueprint one may build many instances of different house objects, all to the same design. It is quite common to use the words ‘class’ and ‘object’ interchangeably, even in the same context, although they mean different things, and it is important to understand the difference. As it happens, everything that is brought into existence in Python is an object, so even integer and floating point numbers are objects, although most of the time you can work without noticing that.

Type
Chapter
Information
Python Programming for Biology
Bioinformatics and Beyond
, pp. 100 - 116
Publisher: Cambridge University Press
Print publication year: 2015

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Object orientation
  • Tim J. Stevens, MRC Laboratory of Molecular Biology, Cambridge, Wayne Boucher, University of Cambridge
  • Book: Python Programming for Biology
  • Online publication: 05 February 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9780511843556.008
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Object orientation
  • Tim J. Stevens, MRC Laboratory of Molecular Biology, Cambridge, Wayne Boucher, University of Cambridge
  • Book: Python Programming for Biology
  • Online publication: 05 February 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9780511843556.008
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Object orientation
  • Tim J. Stevens, MRC Laboratory of Molecular Biology, Cambridge, Wayne Boucher, University of Cambridge
  • Book: Python Programming for Biology
  • Online publication: 05 February 2015
  • Chapter DOI: https://doi.org/10.1017/CBO9780511843556.008
Available formats
×