Page 2 of 5
Re: OO concepts
Posted: Mon Feb 02, 2009 12:00 pm
by jaoudestudios
Once you've done OOP you'll never go back

- especially for common libraries you use over and over again!
Re: OO concepts
Posted: Mon Feb 02, 2009 12:51 pm
by JAB Creations
Apollo wrote:What does that have to do with OO vs procedural?
A class executes once and remains in the memory, it doesn't have to be executed each time it's called. A function does execute every time you call it. So my point was in example regex (which you want to avoid as much as possible) would be better executed inside of a class then a function to reduce server load. I hope that's worded better?

Re: OO concepts
Posted: Mon Feb 02, 2009 12:59 pm
by Eran
An object still executes logic inside methods, which are the same as functions. Apollo was correct on this, this is not where OO and procedural styles are differentiated.
Re: OO concepts
Posted: Mon Feb 02, 2009 1:15 pm
by josh
Objects are just namespaced collections of functions that share data. functions encapsulate business logic, and you pass them data. objects encapsulate the functions with their data combined, so you ask the object to perform the function and instead of having to pass arguments on each function call, you can have multiple objects instantiated for each class, each with their own state. Hope this helps you guys contrast the 2 paradigms.
Re: OO concepts
Posted: Mon Feb 02, 2009 2:03 pm
by Christopher
jshpro2 wrote:Objects are just namespaced collections of functions that share data.
While I technically agree with this statement, this is my complaint about what Apollo said. That is a very big JUST in your statement. Yeah, maybe it is a small syntactical difference -- but look at the world of difference between procedural and OO design and programming. OO revolutionized programming the same way Structured Programming did. As I said earlier, to minimize the effect on design and programing of
"just namespaced collections of functions that share data" is to misrepresent the importance of OO.
Re: OO concepts
Posted: Mon Feb 02, 2009 2:28 pm
by josh
Well yeah that's all they are syntactically was my point, using "just" probably wasn't terribly accurate, I was just trying to make it seem less daunting to understand. The implications or benefits of using objects includes far more than preventing name collisions. Its an entire new paradigm, but the thing is if they don't understand OO they're not gonna understand what a paradigm is, since they only know of 1 paradigm they have nothing to contrast it with, truly the only way to understand it is to use it, and use it more, and more, and read about it, and use it some more, etc...
Re: OO concepts
Posted: Mon Feb 02, 2009 4:32 pm
by Christopher
The amazing think it that a fairly simple syntactical structure can open up such a huge panorama of new design possibilities. Go Simula 67 and Norge!
Re: OO concepts
Posted: Mon Feb 02, 2009 4:44 pm
by mickeyunderscore
Personally I'd consider an object much more complex than just 'namespaced collections of data' (that would describe an associative array IMO). Yes they are that, but they are so much more on top of that. Objects can be used to abstract complex business logic into separate objects which can then manage themselves and look after their own data.
Objects also allow great flexibility through polymorphism, you can allow a class to select one of it's children for a specific job which isn't known until runtime, this being no problem as the children override or extend the base functionality and share the same interface methods as the parent. This is fantastic as you can turn a mess of complex if statements into a nice polymorphic class heirarchy.
And of course you get the benefits of easy code-reuse, being able to easily extend a class to add functionality or take a class or set of classes (as OO promotes cohesive code, uncoupled from the application it sits in) and plug it straight into another application.
I think the majority of problems with OO are due to misunderstanding rather than inherent problems with OO. e.g. people considering OO a magic bullet, or over-engineering a problem by being too trigger-happy with design patterns e.g. I saw a several hundred line 'Hello World' application which used many design patterns as an example and a warning.
On the original post, as Chris and pytrin both say, I would advise learning the basics before moving onto OO. OO can be difficult to grasp (there are a lot of concepts) and if you are a novice at both PHP and programming I don't think you should add 'novice of OO' to your troubles. Learn to program PHP and then learn to program OO PHP.
Most likely, by the time you are writing applications complex enough to warrant the use of OO, you will be ready to begin learning OO.
Re: OO concepts
Posted: Mon Feb 02, 2009 6:16 pm
by nor0101
Seems like we drowned the OP in the details!
Don't forget that in addition to the stack space consumed by a function call's activation record, Objects also take up heap space as dynamically allocated memory. Or alternately, that the "new" keyword is semantically analogous to the "malloc" library function in C...
Re: OO concepts
Posted: Mon Feb 02, 2009 6:23 pm
by Christopher
nor0101 wrote:Don't forget that in addition to the stack space consumed by a function call's activation record, Objects also take up heap space as dynamically allocated memory. Or alternately, that the "new" keyword is semantically analogous to the "malloc" library function in C...
Actuallystack and heap space are exactly the kinds of things you are not supposed to think about in languages like PHP...

Re: OO concepts
Posted: Mon Feb 02, 2009 6:26 pm
by nor0101
arborint wrote:Actuallystack and heap space are exactly the kinds of things you are not supposed to think about in languages like PHP...

Well... yeah. That's what I was getting at. I think the OP was looking for a response in more general terms than all of this.
Re: OO concepts
Posted: Mon Feb 02, 2009 6:36 pm
by Christopher
nor0101 wrote:Well... yeah. That's what I was getting at. I think the OP was looking for a response in more general terms than all of this.
Yeah ...
My answers to the OP would be:
diG1tY wrote:is it required to use the OO capabilities?
No
diG1tY wrote:When would it be appropriate to use classes and objects?
Always
diG1tY wrote:Is there any advantage of using OO and objects over the 'other' way?
Yes, too many advantages to go into in detail, see posts above
Re: OO concepts
Posted: Mon Feb 02, 2009 6:48 pm
by nor0101
@arborint: Agreed. Going the OO route forces a different conceptualization of the problem domain. Apparently it not only produces better code, but better programmers. I've heard that programmers who begin using Objects early in their careers are better able to adapt to using other paradigms such as functional, logic, etc.
Re: OO concepts
Posted: Mon Feb 02, 2009 10:14 pm
by josh
mickeyunderscore wrote:Personally I'd consider an object much more complex than just 'namespaced collections of data' (that would describe an associative array IMO). Yes they are that, but they are so much more on top of that. Objects can be used to abstract complex business logic into separate objects which can then manage themselves and look after their own data.
Dont know if that was directed to me. I didn't say all they do is encapsulate data. I specifically mentioned it adds data to behavior, not the other way around.
Re: OO concepts
Posted: Tue Feb 03, 2009 3:34 am
by mickeyunderscore
Sorry I think I missed your point on that.