Pillars of Object Oriented Programming (in Python)

https://pixabay.com/photos/lens-camera-lens-focus-focusing-1209823/

Abstraction

https://pixabay.com/photos/monkey-zoo-animal-world-observing-2195107/
class Animal(object):

def __init__(self, name):
self.name = name
self.size = None
self.species = None
self.food_type = None
self.color = None

def make_noise(self):
return("Roaaaaaaaaar!")

Encapsulation

class Animal(object):

def __init__(self, name):
self.name = name
self.size = None
self.species = None
self.food_type = None
self._color = None

def color(self):
return(f"This animal is {self._color}")
tiger = Animal("Tony")
tiger._color = 'Orange'
tiger.color()

Inheritance

https://pixabay.com/photos/animal-tiger-big-cat-safari-1868911/
class Animal(object):

def __init__(self):
self.size = None
self.species = None
self.food_type = None
self.color = None

def make_noise(self):
return("Roaaaaaaaaar!")

class Tiger(Animal):

def __init__(self):
super().__init__()
self.species = "Panthera tigris"
self.size = "Large"
self.food_type = "Carnivore"
self.color = "Orange"
Tony = Tiger()
Tony.make_noise()

Polymorphism

https://pixabay.com/photos/snake-green-macro-animal-zoo-1634293/
class Snake(Animal):

def __init__(self):
super().__init__()
self.size = "Medium"
self.food_type = 'Carnivore'

def make_noise(self):
return("SSSSsssss!")

Concluding Remarks

--

--

--

Data Scientist | Health Enthusiast | Learner

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

8 Tips for Successful Project Management

Angular — intercept your http errors

Http interceptor basic flow

What About Bob? — How This Old Movie Changed My Code

What about Bob?

Coding WebApps on an iPad in 2019

MySQL Shell Python mode blog posts compilation

How to VPN connect between Azure and AWS with Managed Services.

Product Owner, Development Team and Business Value

Getting Lost in Unsafe Region

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Kundycki

John Kundycki

Data Scientist | Health Enthusiast | Learner

More from Medium

Python 3.10 — Better error messages

Beginners Python Series — Datatypes

How I Learned to Code

Level-up Lists with List Comprehension!