What object-oriented programming is NOT

I’ve made this argument several times, but object-oriented programming is MORE (much more) than knowing how to write a class. It’s a “paradigm” (as WikiPedia calls it) or a “model” (that’s Tech Target’s word). I call it an “approach”… but it’s an approach to application-building.

OOP is not about how you write your code… it’s about how you build your applications. That may not make sense, at first… but it is an important distinction. So, let’s look at some code and see if we can make this clear.

So, the first thing object-oriented programming is not is…

Object-Oriented Programming Is Not Writing a Class

You use classes, but that’s not what it IS. A lot of times what I see developers do is take a set of functions like this:

<?php
function my_func_one() {
    // do stuff
}

function my_func_two() {
    // do stuff
}

And, just do this with it:

<?php
class MyClass {
    function my_func_one() {
        // do stuff
    }
    
    function my_func_two() {
        // do stuff
    }
}

That’s not object-oriented programming… that’s namespacing. Which is fine, but you’d be better off just using actual namespaces like this:

<?php
namespace App\Functions;

function my_func_one() {
    // do stuff
}

function my_func_two() {
    // do stuff
}

// Note: prior to PHP 5.6 this wouldn't work because importing function and
// constant names wasn't supported. 5.6+ DOES support this.

It’s simpler syntax, it’s easier to update your existing procedural code and you’d being using the “right tool for the right job” in my opinion.

Object-Oriented Programming Is NOT Static

Another one I see is heavy use of the “static” keyword. So something like this:

<?php
class MyClass {
    public static function my_func_one() {
        // do stuff
    }
    public static function my_func_two() {
        // do stuff
    }
}

MyClass::my_func_one();
MyClass::my_func_two();

This is really the same mistake as before, just more fancy-looking. The reason you’d do this is to put your functions into a class and be able to call them in the procedural way you’re used to… but not have to “mess with all that instantiating nonsense”. This, again, is really just namespacing. (There are proper uses of “static” in OOP, but they’re fairly rare. So, if all or most of your class methods are static… that’s not object-oriented programming.)

Object-Oriented Programming Is NOT MVC

This will ruffle a few feathers probably, but OOP and MVC are, in fact, two different things. OOP is an “approach” (model, paradigm) to application-building. MVC is one, of many, application design patterns that employ OOP principles. So, you can “do OOP” without MVC.

I bring this up because MVC’s popularity (for good reason) tends to make people think that’s all there is. “If I’m gonna OOP, I gotta MVC.” But, there are plenty of other patterns out there… some of which I personally prefer to MVC.

That’s why in my object-oriented programming course, I show you MVC, but I also show you another design pattern… one I personally like better. To challenge you to think about it different ways and develop what works for you… not just follow what everyone else is doing.

That and a lot of the frameworks that employ MVC principles actually use a distorted form of it… but that’s a topic for another time.

What Object-Oriented Programming IS

I’ll re-iterate… it’s an entire “re-thinking” of how you build your applications. Procedural coding tends to focus on process over data. We think of what we need to DO first. We need to process this form data or edit this blog post. And, those processes tend to be what drives our application design decisions.

OOP is different. It focuses on the data first. Instead of breaking your applications down into processes, you break into down into objects. And, objects here is used in the general sense… a phone is an object, a remote is an object… these things are literal objects in the real world.

So, we build our applications in the same way we view the world in real life. We break a CMS down by “post”, “category”, “tag”, “author”, “comment”… and we think about our data model FIRST. Then, we write the code to create, read, update and delete.

It’s Not Your Fault

Now, I know you might feel like I’m ragging on you if you’ve done any of this stuff. I’m not. I did all the same stuff. Probably anyone who’s made the switch from procedural to object-oriented programming did this same stuff.

I think most coders’ minds are naturally oriented to think in processes. So, breaking out of that is difficult. But, ultimately, for large, complex applications OOP is a better way to build. It’s easier to think about your application mentally in this way. Your code is often more organized. And, it’s more in line with how your end-user sees your application.

If you’d like to dive into all this more, then check out my object-oriented programming course. I’ll clear up all the confusion you might have surrounding OOP and show you how to build professional PHP applications using object-oriented programming.

Who else wants to build a thriving freelance business?

I’ve helped 39,413 other freelancers start and grow thriving freelance businesses. Are you next? Subscribe to my Freelance Secrets newsletter and I’ll show you how.

You might also like

Facebook
Twitter
LinkedIn
Reddit
Pinterest
John Morris

JOHN MORRIS

I’m a 15-year veteran of freelance web development. I’ve worked with bestselling authors and average Joe’s next door. These days, I focus on helping other freelancers build their freelance business and their lifestyles.

Who else wants to build a thriving freelance business?

I’ve helped 39,413 other freelancers start and grow thriving freelance businesses. Are you next? Subscribe to my Freelance Secrets newsletter and I’ll show you how.

Success Stories

Ready to add your name here?

Tim Covello

Tim Covello

75 SEO and website clients now. My income went from sub zero to over 6K just last month. Tracking 10K for next month. Seriously, you changed my life.

Michael Phoenix

Michael Phoenix

By the way, just hit 95K for the year. I can’t thank you enough for everything you’ve taught me. You’ve changed my life. Thank you!

Stephanie Korski

Stephanie Korski

I started this 3 days ago, following John’s suggestions, and I gained the Upwork Rising Talent badge in less than 2 days. I have a call with my first potential client tomorrow. Thanks, John!

Jithin Veedu

Jithin Veedu

John is the man! I followed his steps and I am flooded with interviews in a week. I got into two Talent clouds. The very next day, I got an invitation from the talent specialists from Upwork and a lot more. I wanna shout out, he is the best in this. Thanks John for helping me out!

Divyendra Singh Jadoun

Divyendra Singh Jadoun

After viewing John’s course, I made an Upwork account and it got approved the same day. Amazingly, I got my first job the very same day, I couldn’t believe it, I thought maybe I got it by coincidence. Anyways I completed the job and received my first earnings. Then, after two days, I got another job and within a week I got 3 jobs and completed them successfully. All the things he says seem to be minute but have a very great impact on your freelancing career.

Sarah Mui

Sarah Mui

I’ve been in an existential crisis for the last week about what the heck I’m doing as a business owner. Even though I’ve been a business for about a year, I’m constantly trying to think of how to prune and refine services. This was very personable and enjoyable to watch. Usually, business courses like this are dry and hard to get through…. repeating the same things over and over again. This was a breath of fresh air. THANK YOU.

Waqas Abdul Majeed

Waqas Abdul Majeed

I’ve definitely learnt so much in 2.5 hours than I’d learn watching different videos online on Youtube and reading tons of articles on the web. John has a natural way of teaching, where he is passionately diving in the topics and he makes it very easy to grasp — someone who wants you to really start running your business well by learning about the right tools and implement them in your online business. I will definitely share with many of the people I know who have been struggling for so long, I did find my answers and I’m sure will do too.

Scott Plude

Scott Plude

I have been following John Morris for several years now. His instruction ranges from beginner to advanced, to CEO-level guidance. I have referred friends and clients to John, and have encouraged my own daughter to pay attention to what he says. All of his teachings create wealth for me (and happiness for my clients!) I can’t speak highly enough about John, his name is well known in my home.

Sukh Plaha

John is a fantastic and patient tutor, who is not just able to share knowledge and communicate it very effectively – but able to support one in applying it. However, I believe that John has a very rare ability to go further than just imparting knowledge and showing one how to apply it. He is able to innately provoke one’s curiosity when explaining and demonstrating concepts, to the extent that one can explore and unravel their own learning journey. Thanks very much John!

Mohamed Misrab

Misrab Mohamed

John has been the most important person in my freelance career ever since I started. Without him, I would have taken 10 or 20 years more to reach the position I am at now (Level 2 seller on Fiverr and Top Rated on Upwork).

Who else wants to build a thriving freelance business?

I’ve helped 39,413 other freelancers start and grow thriving freelance businesses. Are you next? Subscribe to my Freelance Secrets newsletter and I’ll show you how.