Why do object oriented principles matter, anyway?
Last week I was chatting with a friend who was asking me about object oriented programming. He asked me a pointed question that I thought deserved a broad and public answer. His question? "Why do these object oriented principles matter, anyway?"
It's a good question. You probably came to PHP writing procedural code, never caring about object oriented development. And maybe you've heard that object oriented development is the way of the future, but for now you haven't seen much of a need for it. You wonder, why does it matter?
There are three reasons you should care about understanding and mastering object oriented programming.
Object oriented programming is about reuse.
Writing object oriented applications is about being able to reuse code that you've written elsewhere.
For example, if you've developed a great database API, you may want to take that along to other applications. Rather than starting from first principles, this object gives you a starting point that you can use in other applications.
Reusing code reduces the time it takes to write new code. Period.
Frameworks are impossible without object oriented development.
Imagine Zend Framework or Laravel without the object oriented model. Would it be possible to create these frameworks with straight procedural code? WordPress has tried; diving into that code base is a sure way to end the day with a headache.
Simply put, the patterns and practices used in modern frameworks rely upon and require understanding object oriented principles. It's difficult if not impossible to work effectively within these frameworks without understanding these concepts.
PHP isn't the only language you'll ever use.
For most of us, we use PHP regularly, but it's far from the only langauge we'll ever use. In fact, most of us will work with Javascript, Python and maybe even some Ruby at some point or another. Those three languages I listed are all 100% object oriented.
PHP allows us to work with procedural code, but in the scheme of modern languages this is an exception, not a rule. You can write procedural code with Python or Javascript, but it's incredibly difficult. And since everything in Python and Javascript is an object, well, you're doing object oriented programming whether you want to or not.
It's a good question. You probably came to PHP writing procedural code, never caring about object oriented development. And maybe you've heard that object oriented development is the way of the future, but for now you haven't seen much of a need for it. You wonder, why does it matter?
There are three reasons you should care about understanding and mastering object oriented programming.
Object oriented programming is about reuse.
Writing object oriented applications is about being able to reuse code that you've written elsewhere.
For example, if you've developed a great database API, you may want to take that along to other applications. Rather than starting from first principles, this object gives you a starting point that you can use in other applications.
Reusing code reduces the time it takes to write new code. Period.
Frameworks are impossible without object oriented development.
Imagine Zend Framework or Laravel without the object oriented model. Would it be possible to create these frameworks with straight procedural code? WordPress has tried; diving into that code base is a sure way to end the day with a headache.
Simply put, the patterns and practices used in modern frameworks rely upon and require understanding object oriented principles. It's difficult if not impossible to work effectively within these frameworks without understanding these concepts.
PHP isn't the only language you'll ever use.
For most of us, we use PHP regularly, but it's far from the only langauge we'll ever use. In fact, most of us will work with Javascript, Python and maybe even some Ruby at some point or another. Those three languages I listed are all 100% object oriented.
PHP allows us to work with procedural code, but in the scheme of modern languages this is an exception, not a rule. You can write procedural code with Python or Javascript, but it's incredibly difficult. And since everything in Python and Javascript is an object, well, you're doing object oriented programming whether you want to or not.
Comments
Post a Comment