WSQ03 – Object Oriented Programming

--Originally published at oscarlopez95blog

After I’ve seen this video i understand the basics of object oriented programming.

Object oriented programming is really simple once you get the hang of it, you just have to think (as the language says) in manner of objects, you can ask yourself this questions when you want to create something:

Is this object part of a bigger category?

How can I associate this objects?

Who or what will be able to access this?

You have to remember than Object Oriented programming is really focused on reusing and recycling code, so you have to try your best to have it well organized. And you can do so with classes, inheritance and encapsulation.

Inheritance is when two things have a “this is a…” relationship, for example, humans and cats are mammals, but not all mammals are just either humans or cats, so if you have a class human and a class cat, both of them inherit from the mammal class, not the other way around.

Encapsulation is basically asking yourself as you code “Who or what will be able to access this?” If you want that specific method or attribute to be accessed just by the class it was created on, you make it private. If you want any class to be able to access it, then make it public.

An easy example for this is when you have something that many classes use, but maybe in different ways. Humans and cats walk, but they don’t walk the same way.


WSQ03 – Object Oriented Programming