Page 1 of 1
OOP and other questions
Posted: Sat Jun 08, 2002 2:49 am
by MattF
Please could someone clever clear up a few points for me?
Why is
Object
Oriented
Programming so good? ie why is it better to use classes that to use simple functions?
What is all this?
Code: Select all
function is_edible() {
return $this->edible;
}
function what_color() {
return $this->color;
}
( Found here:
http://www.php.net/manual/en/ref.classobj.php )
Can classes be started on one page eg $user = new class();
on one page and then on the next page somethinglike $user = resume class(); ?
What does the & mean on the front of a string?
Sorry about this but I don't know much about it and I know lots of clever people do it so I want to!
o.o
Posted: Sat Jun 08, 2002 3:40 am
by vio
u down with oop yea u know me o_o
OOP stuff
Posted: Sat Jun 08, 2002 1:52 pm
by BDKR
OOP is considered good as it helps with organization of large projects, data (and method) encapsulation, and abstraction. Functions are good of course, but in using objects, code can become more modular. It's a cool concept that I'm not doing justice too in this explanation. You really should look into it a good deal more as understanding it will help you on a multitude of levels.
As for ....
Can classes be started on one page eg $user = new class();
on one page and then on the next page somethinglike $user = resume class(); ?
.... I think you want to take a look at serialization. However, if there is not much data to be moved from one page to the next, just stick it in a hidden field. Otherwise, store it in a db, session, or file, and instantiate the new object with the data. You can prolly guess that I don't serialize objects.
Lastly, the "&" is used to denote "by reference". You should check it out in the manual. But here is a short example.
Code: Select all
# Example 1
$Sarge = $Grunt;
// This will copy $Sarge to $Grunt so you then have to variables.
# Example 2
$Sarge = &$Grunt;
/*
This will make $Grunt "refer" or "point" to $Sarge as opposed to making a copy. You then have two vars (with different names of course) pointing or referring to the same place in memory. If you make a change to $Grunt, it also changes $Sarge, and vice versa.
*/
Hope that helps.....
Big Din K.R.
Posted: Sat Jun 08, 2002 1:57 pm
by jason
The problem with a lot of OOP examples and tutorial (mine included) is that while they cover OOP, they don't cover it enough. They leave readers wondering WHY should they use OOP over normal procedural style? OOP is a lot more work for what is initially percieved as no gain.
OOP is best on larger systems when you have multiple developers working on a single system. It essentially allows you, the developer, to create a system, and provied an interface to the system via code for other developer's to use. When you create this interface, you want to protect certain parts of it, and also prevent the coder from doing things they shouldn't do, as well as allow them access to certain parts of the system easily.
Posted: Sat Jun 08, 2002 3:36 pm
by MattF
Thanks that clears tings up a bit, I seem to remember seeing something similar to the &$ things in C++ but I forget what they're called. I am planning on starting a new project possibly with multiple developers so I think I will use some OOP for that. A general thing that I have seen with OOP code is that most people never output anything from classes, they just call them to get data - that way they can be used in any layout and design and still fit in, that would be a main use for it for me. Thanks for your prompt replys

Posted: Sun Jun 09, 2002 8:49 am
by jason
Just as a minor suggestion: Don't use OOP just to use OOP. Use it where it's needed. Objects in PHP do add to processing time.