What is Object-Oriented Programming 
Tags: todayilearned
Published: 2020-01-04 07:40:31


What Is Object-Oriented Programming?

Object-Oriented Programming(OOP) is a programming paradigm to organize code on the concepts of objects. An Object is when you bundle data properties and behaviors(functions/methods) together.

Why use OOP?
OOP allows you to create large-scale applications with modules that are independent of one another. 

Key terms

Classes and Instances

A Class is a blueprint for objects.
 
An object is an instance of a class.

Key Concepts to OOP 

APIE - Abstraction, polymorphism, Inheritance, encapsulation 

**Abstraction** - Is the overall essence of an object. What qualities/features trigger the overall association of the object. 

For example when I say the word `dog`. You automatically know what I'm talking about.

I did not have to name a specific example of dog i.e. Golden Retriever to make you understand that I'm just talking about dogs in general. 


**Encapsulation** - Is when you hide or restrict access to data in your program. Many people use the term *black boxing*. A user is only focused on the input and output of a machine and is not concerned with how the machine works. 

We use black boxing every day of our lives. For example, when you drive your car. Do you need to know how your engine works in order to drive a car? No. All you need to know is that you need gas and you stick the key in the ignition in order to make the car move forward. 


**Inheritance** - Is when a class receives attributes and functions from another class. It's similar to us humans. You inherited characteristics from your parents but you are not a total clone of your mother or father. 

To test that two classes have inheritance relationship use the `IS-A` test. 

Let's say we have a parent class(superclass) called Toy Dogs. A chihuahua *IS-A* toy dog. A Pug *IS-A* toy dog. A Great Dane *IS-NOT* a toy dog.

![Toy Dog Chart](https://i.dailymail.co.uk/i/pix/2014/03/24/article-2588177-1C8944BB00000578-801_964x519.jpg)
[Image Source](https://www.dailymail.co.uk/sciencetech/article-2588177/The-family-tree-DOGS-From-tiny-chihuahuas-great-danes-infographic-reveals-single-breed-related.html)

A concept similar to inheritance is composition. Composition is when two or more objects make another object. The relationship is one of ownership. Use the test *HAS-A* to check if its a composition.

A car *HAS-A* engine. 
A Jedi *HAS-A* lightsaber.
A pokemon trainer *HAS-A* Pokeball.


**Polymorphism** - is the ability to take several forms. In oop we use overriding and overloading to achieve this.

Overriding is when a subclass changes the functionality of a method with the same name.


Overloading is when a class has multiple methods of the same name.



Other OO* terms

|OOA | Object-Oriented Analysis | Understanding your problem
|OOD | Object-Oriented Design   | Create/ Design your solution to the problem
|OOP  | Object-Oriented Programming | Programming your solution




**Further Reading and Resources**

Object-Oriented Programming for Python by Dusty Phillips
UML Distilled by Martin Fowler
Head First Object-Oriented Programming and Analysis
[How to learn Software Development and Architecture - a Roadmap](https://www.freecodecamp.org/news/2019-web-developer-roadmap/)
[FreeCode Camp 2019 Web Developer Roadmap](https://www.freecodecamp.org/news/software-design/)
[What is object-Oriented Programming-Real Python](https://realpython.com/python3-object-oriented-programming/#what-is-object-oriented-programming-oop)