DEV Community

Ngan Kim Khong
Ngan Kim Khong

Posted on

An "Aha" moment about Object Oriented Programming

I'm not sure how to hashtag my blog to beginner only. If you're an experience developer, you can skip this blog :P.

This concept I'm about to write, is so fundamental with many experience developers, yet so strange to a newbie like me.
Also, I'm not sure everything I understand is correct, so please correct me when I'm wrong, and don't take this blog to heart, but to the surface, make things easier to blog.

Since learning Java, I realized that by learning Python, Ruby and Javascript, I missed one of the most important part in programming: practicing OOP (Object Oriented Programming) concept throughly. Unlike Java or C#, languages like Javascript are more about functional programming, it was created for functional programming. Much later, Javascript started implement classes so it can do OOP things. Up until my recent internship, which forced me to use pure React without Hooks (Hooks makes you use functional components), I don't have much experience with OOP. And while unable to negotiate my boss to use functional components with my project, I had to crawl back to the fundamental and started learning about classes. It was painful partly because of the syntax, but I don't know why I had to do it, until I start getting the hang of it and then connecting things with what I've learned, I started to embrace the resembles of React to classes.

Now, I mentioned that Java helped me understand OOP. But, you don't need to know Java. In Java, you must write everything within a class, want to write a function ? Put it in a class. Can't do it without classes. That's all you need to know. Javascript has Class as well, even though javascript was not created to use Classes, but it eventually have Classes. So, you can think of Javascript's Classes are for OOP wannabes.

In summary, class resembles OOP and OOP resembles class. React is created based on OOP. So, React resembles OOP and resembles Class. React == Class == OOP . I know, my silly comparisons, lol.

With this realizations, I started to be able to imagine React is a blue print of a class, React Components are like, a function in a class, that can take in props ad parameter arguments, and pass it around and between other functions. And states in React, is like a local variable inside a function. And you can go on and on...

In my opinions, I was learning many things that are very shallow at the same time and for a while I couldn't connect anything with anything. The moment I realized that this concept and the connections between classes and OOP, it feels like I now discovered the universe's fundamental blocks. And I'm glad that this discovery doesn't make things harder for me, but things gets easier AND, make me excited to learn more!

Oldest comments (1)

Collapse
 
solowon27 profile image
solowon27

I like the way you explain things in a simple manner! Bravo