OOP

Cards (21)

  • Object-oriented technology
    Models real-world objects
  • Real-world objects
    • table
    • television
    • chair
  • Software objects
    Can represent real-world objects and other (living or non-living) entities
  • The Python programming language uses objects and classes in building programs
  • Objects
    • State
    • Behavior
  • Dog object
    • Name, color and breed (state)
    • Bark, jump, roll-over (behavior)
  • Class
    Objects with similar characteristics can fall under one class
  • Dog class
    • Bulldog
    • Poodle
    • Chihuahua
  • Class

    Template or blueprint from which objects are derived
  • Class
    • Attributes (state/variables)
    • Methods (behavior)
  • Defining a class
    Class Classname: statements...
  • Class members
    • Fields (attributes)
    • Methods (behavior)
  • Class instantiation
    Creating an object out of a class
  • __init__ function
    Automatically called when creating a new object, allows class to initialize object attributes
  • The self parameter is a reference to the current instance of the class, and is used to access variables that belong to the class
  • __ indicates a private variable in Python
  • Class variables are declared at the class level, instance variables are declared in the __init__ method
  • Inheritance is a mechanism that allows a class to inherit properties and behaviours from another class
  • Inheritance
    Derived class (subclass/child class) inherits from base class (superclass/parent class)
  • Method overriding
    Subclass provides specific implementation of a method already provided by superclass
  • The version of a method that is executed is determined by the object used to invoke it, not the reference variable type