Page 1 of 1
object oriented versus procedural
Posted: Sat May 17, 2008 3:52 pm
by josh22x
I am new to PHP and just realized that there are two coding styles OO and Procedural. What is the difference really, and which should I use??
Thanks!
Re: object oriented versus procedural
Posted: Sat May 17, 2008 4:04 pm
by Christopher
You will use both in PHP. Use OO to create the structure of your program with classes. Within class methods you will have some procedural code in PHP.
Re: object oriented versus procedural
Posted: Sat May 17, 2008 10:16 pm
by josh22x
What is the real difference between the two different methods?
Thanks!
Re: object oriented versus procedural
Posted: Sat May 17, 2008 10:33 pm
by Christopher
There is some overlap in the sense that you can do things like Modularity, Layering and Dependencies, etc. with either. And I should note that when you say "procedural" you are probably actually referring to Structured Programming.
These days the main difference is that there is very little literature or support for procedural programming. Almost everything is OO. PHP and C are the only major languages that are not completely OO. OOP provides a number of benefits, both directly due to the class construct, from design concepts associated with OOP, and from a number of distinct things you can do once you have objects. If you want to discuss anything more than very simple PHP programs then you will need to know how to discuss them using OOP concepts and patterns.
Re: object oriented versus procedural
Posted: Sun May 18, 2008 10:20 am
by josh22x
I guess what I am confused about is the actual coding style in each method. Could you give me an example of each, to show me the difference??
Thanks!
Re: object oriented versus procedural
Posted: Sun May 18, 2008 1:04 pm
by Christopher
That is too big a subject to really cover in a simple response. Given your questions, I would recommend looking at the various PHP/OOP/Patterns books around.
This one is very good and very in-depth:
http://www.amazon.com/PHP-Action-Object ... 467&sr=8-4
This one is more an intro to OOP basics:
http://www.amazon.com/Object-Oriented-P ... _b_title_3
Re: object oriented versus procedural
Posted: Sun May 18, 2008 1:30 pm
by josh22x
Thanks!
Re: object oriented versus procedural
Posted: Sun May 18, 2008 5:34 pm
by slightlymore
There is a massive difference that (as arborint pointed out) books have been written about.
OO programming is newer, and is supposed to be more human readable. I used to not understand OO programming, and was probably a little scared of it, but if you learn and understand it, I think that it's one of the most useful things you'll know.