To object orient code or not?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
salmon
Forum Newbie
Posts: 9
Joined: Tue Jun 24, 2008 5:03 pm

To object orient code or not?

Post by salmon »

Should I be programming php in object oriented style? Is "unstructured" out of date completely?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: To object orient code or not?

Post by requinix »

Like every single thing related to programming, whether you should use it or not depends on the situation.
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: To object orient code or not?

Post by Griven »

Like Tasairis said, it depends on what you're doing.

If your program is a larger one, and will require the reuse of code, then you should look into using an OOP style. This will encourage DRY programming (Don't Repeat Yourself).

However, if your project is smaller and won't require much (if any) reuse of code, then it's more economical from a time standpoint to use a procedural style of coding.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: To object orient code or not?

Post by josh »

It doesn't matter, that are just heuristics that if followed yield in better designs. Better in terms of scientifically measurable. These are things like

Coupling (minimize)
Cohesion (maximize)
Duplication (minimize)
Cyclomatic Complexity (Minimize)
Test Coverage / Test Harnesses (maximize)

Google each one in turn and read up :wink:

(FYI most programmers would agree object orientation does a better job at achieving these goals)
Post Reply