OPP Basics

Gary Cordero Rosa
3 min readDec 14, 2020

--

I recently graduated from a software engineering boot camp and during the whole process, my cohort mates and I were learning how to code and mastering many technologies along the way. During this time we learn to code following the guidelines of object-oriented programming (OPP), and today I decided to dive deeper into what is object-oriented programming.

Object Oriented Programming (OPP) is a programming paradigm base on objects and the interaction between one another. Objects contain features, commonly called attributes or properties and methods that allow them to interact with those properties.

Objects most commonly belong to a class, and are referred as instances of a class which identify their type. To better understand this concept, imagine yourself as an object of the class human, all human share many of the same characteristics we all have a name, age, height,weight, blood type, but the value of those characteristics change from object to object, making the class something like a blueprint.

Objects as well as characteristics, also contains specific behaviors, also called methods. These methods allow objects to either interact with their features or with other objects. Again think think of us humans, we constantly use methods to interact with other objects.Everytime we introduce ourselves we call the method introduce() or when we eat we called the method eat().

Object-Oriented Programming Principles

The four principles of object-oriented programming are encapsulation, abstraction, inheritance, and polymorphism.

Encasuplation, is a concept in which objects bind their attributes and methods together and keeps them safe from outside interference and misuse. It is all about of protecting the data, that way it can only be access through the proper means and use accordingly. You often see this concept be implemented through the use of access modifiers (private, protected and public).

Abstraction

It is a concept referring to hiding the complexity of how something works and focus on how to used it.

An example of the abstraction would be us walking (), we know how to walk but we don't know how the complex signaling of our brain works in order to achieve that.

Inheritance

Refers to how objects can share similar or some characteristics with other objects from different one or more different classes and instead of implementing the same code in each individual class, another class can be created from where the classes of this objects can inherit from.

An example of inheritance is humans and dogs are mammals and share some property height, weight , etc… and behaviors like eat() and walk(), but even though they are both mammals they are definitely not the same.

Polymorphism, refers to the different ways an object can respond after invoking a method depending of the situation or context.

Example A: Let’s say all mammals can move, humans walk, whales swim, dog trot, etc… Different mammal objects will respond to the same message move differently

Example B: This is an even simple example, let say you can introduce yourselves in different language the method introduce () will have different behavior depending on what language is needed in that specific occasion.

--

--

Gary Cordero Rosa
Gary Cordero Rosa

Written by Gary Cordero Rosa

Flatiron School Software Engineering Student

No responses yet