Why should you use object-oriented programming?
Video: Why should you use object-oriented programming?There are a number of very practical reasons for using object-oriented programming, and not just because it looks good on paper. The short reason? Object-oriented programming organizes projects into consistent, manageable pieces. As a developer, I've come to really appreciate well-organized code, as it saves time and money. In comparison, procedural programming is a set of step-by-step instructions that the computer must follow. A procedural program can consist of a series of conditions, and function calls for logic, but the end result is very linear.
Viewers: in countries Watching now:
Whether you're enhancing or optimizing existing code or just starting from scratch, there's never a better time to start integrating object-oriented design techniques. This course shows how to integrate the principles of object-oriented programming into the build of a PHP-driven web page or application. After an overview of what objects and classes are and why they should be used, author Jon Peck dives into creating and instantiating objects, then defining the class relationships and interactions that will form the basis of your coding arsenal. The course also shows how to leverage PHP objects and implement design patterns, and looks at steps you can take to continue adding to your programming tool belt.
- Historical overview of object-oriented PHP
- Defining classes
- Creating a method/object context with $this
- Accessing classes without instantiation
- Creating a database class
- Extending and abstracting classes
- Cloning and comparing objects
- Error handling with exceptions
- Implementing design patterns, such as the factory and strategy patterns
Why should you use object-oriented programming?
There are a number of very practical reasons for using object-oriented programming, and not just because it looks good on paper. The short reason? Object-oriented programming organizes projects into consistent, manageable pieces. As a developer, I've come to really appreciate well-organized code, as it saves time and money. In comparison, procedural programming is a set of step-by-step instructions that the computer must follow. A procedural program can consist of a series of conditions, and function calls for logic, but the end result is very linear.
Meaning, program execution is like a straight line, rigid and inflexible. There's nothing wrong with procedural programming, and for small projects, it can be a good solution. The problem comes when you scale up. You may find yourself defining arrays with long descriptive keys, or passing large numbers of global variables between scripts, or even searching for a non-fatal bug across a dozen squares with thousands of lines of code with little indication of which component is at fault. Object-oriented programming introduces structure intended to avoid the scaling and maintenance issues.
Throughout this course, I am going to explore a number of features of object-oriented programming, including abstraction, which defines data and program structures using a representation of meaning, while hiding the implementation itself. This allows for the use of human readable terminology to be used as part of the software. Next is encapsulation, which exposes functionality while restricting access to low-level components and data. You can also introduce a hierarchy where properties and behavior from pre-existing classes are inherited, which allows for incremental development.
Another feature is modularity, where functionality is broken into modules that accomplish one task, and contain everything necessary to complete said task. Instead of trying to deal with one large problem, a number of smaller sub-problems work together to solve the bigger problem. And finally, polymorphism, which is the ability to interact with classes in the same way without having to know exactly which class they are. By using object-oriented programming, you can build small components that can be easily maintained and expanded upon without messing up the entire program. That way, you can create and test the program in small pieces, rather than trying to deal with huge, messy code.
But has PHP always supported this kind of object-oriented programming?
Find answers to the most frequently asked questions about Object-Oriented Programming with PHP .
Here are the FAQs that matched your search "" :
- Q: I'm not seeing warnings or errors in my environment like the video; why not?
- A: Your PHP configuration is probably configured not to show them to you. This is often true on commercial web hosts and is often the default. Fortunately, there are multiple ways of resolving this.
The easiest way would be to explicitly enable error reporting at the top of the PHP script you wish to debug.
error_reporting(E_ALL | E_STRICT);
Alternatively, if you have access to your php.ini file and you want to always have error reporting on, change error_reporting = to a development friendly value of
error_reporting = E_ALL | E_STRICT
then change display_errors = to
display_errors = On
Finally, if access to the php.ini file is not available, you can add the following directives to your .htaccess or VirtualHost configuration for Apache:
php_value error_reporting 32767
php_value display_errors 1
If you would like a development optimized development environment like the one utilized in this course, see Up and Running with Linux for PHP Developers, here in the lynda.com online training library.
Q: This course was updated on 4/10/2013. What changed?
A: The author rerecorded some of the tutorials to add more background information and better graphics.
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.