Examples of Object-Oriented Programming

Programming Paradigm Concepts

Eleanor Thomas

Senior Data Analytics Engineer

Applications of object-oriented programming

  • Simulations of various types (e.g. stock prices, physics problems)
  • Object-oriented databases (a specific type of database) like MongoDB
  • Problems where many small, similar tasks need to run at the same time (e.g. sorting many independent lists)

Object-oriented programming

Programming Paradigm Concepts

Pros and cons of object-oriented programming

Pros

  • Maintains security of data
  • Allows for parallel development
  • Reusable and maintainable

Cons

  • Code can be slow to run
  • Programs can be longer (more lines of code)
  • Not appropriate for all applications -- inappropriate use results in long, slow programs
Programming Paradigm Concepts

Public and private attributes

  • Public attributes and methods are available throughout the program (default in Python)
    • Dog example: "name" = public attribute
    • Dog example: "bark" = public method
  • Private attributes and methods are only accessible within the class itself (denoted with __ prefix in Python)
Programming Paradigm Concepts

Public vs. private example

class Dog():
    def __init__(self, name):
        self.name = name

self.__hungry = True
def eat(self): self.__hungry = False
lacy = Dog("Lacy") lacy.__hungry = False # This line won't work!!
Programming Paradigm Concepts

Let's practice!

Programming Paradigm Concepts

Preparing Video For Download...