The Basics of Object Oriented Programming

What Is Object Oriented Programming?

Encapsulation

Create a Dog class with a show_dog() method
ruby encapsulation.rb
My name is Sammy
I am 8 years old
I am a golden retriever

Abstraction

Abstraction using a public and a private method
16:32 $ ruby abstraction.rb
Traceback (most recent call last):
abstraction.rb:25:in `<main>': private method `get_area' called for #<Rectangle:0x00007fc31484e638 @length=5, @width=5> (NoMethodError)
16:33 $ ruby abstraction.rb
My area is length * width
My area is 25

Inheritance

Dog class has access to all parent methods
17:03 $ ruby inheritance.rb
Child class
Woof Woof
Im snoring

Polymorphism

Polymorphism using Inheritance
17:37 $ ruby polymorphism.rb
Im snoring
Sleepy dog here

The Super Keyword

The super keyword refers to the parent class definition of snore()
18:15 $ ruby polymorphism2.rb
Im snoring
Sleepy dog here

Comprehension Is Key

--

--

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
Aidan McBride

Aidan McBride

I ‘m a Web Developer and a Flatiron coding bootcamp alumni. I currently work in the financial tech industry as a Front End Engineer