Python
  Home arrow Python arrow Page 2 - Object Orientation in Python
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Object Orientation in Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 38
    2005-02-14


    Table of Contents:
  • Object Orientation in Python
  • Another Way to Understand Object Orientation
  • Classes in Python
  • More About Creating Classes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Object Orientation in Python - Another Way to Understand Object Orientation
    ( Page 2 of 4 )

     

    If you still don't understand the concept, let's take a look at your computer. Your computer has its own attributes and methods. For example, if we want to know the clock speed of the computer's processor, we could use access an attribute named clockSpeed:

     

    yourComputer.clockSpeed

     

    We can also overclock the computer by increasing the multiplier by calling a method called modifyMultiplier:

     

    yourComputer.modifyMultiplier()

     

    This would increase the computer's multiplier attribute and increase the clockSpeed attribute. As you can see, the methods of an object perform actions on its data.

     

    Now let's say you bought your computer from a manufacturer named Shiny Silver Computers, Inc. Let's say that your computer is a model named "Basic Computer." "Basic Computer" might be a class. What is a class? A class is basically an outline of the objects within the class. You can compare it to the blueprints of a house. The blueprints would be a class, and the actual house would be an object based on the class. While an object is always very similar to the class on which it is based, its data can vary. For example, you might have requested hat your computer have a blue case with a window.

     

    Or, to use a more technical definition: in object-oriented programming, a class is a template definition of the methods and variables in a particular kind of object. Thus, an object is a specific instance of a class; it contains real values instead of variables.

     

    Now let's say that Shiny Silver Computers, Inc. decides to design a new model based on their "Basic Computer" model. They would subclass the original class. The new class, or subclass, would be based upon the old class, or superclass, but its methods or data might vary, or it might add new methods or data. For example, let's say that the new computer model has a faster clock speed. The clockSpeed attribute would be different. Let's also say that the new model has a button that will turn on lights inside the case. There would be a new method called turnOnLights.

     

    Objects may also interact with each other and message each other. Let's create a screwdriver object. You might want to unscrew a certain screw in your computer, so you would have the screwdriver object call the unscrew method of your computer. The screwdriver object would also pass an argument specifying which screw needs to be unscrewed.

     

    Likewise, you yourself might be an object. You can push the computer's power button by calling its pushPowerButton method. Your computer might then change its powerState variable.

     

    Object orientation makes programming a lot more simple, and it also organizes things. In Python, you will use and manipulate objects regularly.

     



     
     
    >>> More Python Articles          >>> More By Peyton McCullough
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek