|
Posted by Weird-beard on 11/19/05 00:33
Thomas,
In object oriented programming, everything should be an object.
Therefore, you may need classes that only has functions that just do
the job and does not need an instance. Therefore, only static
functioned classes could be used to do that. In oop, you do not just
print_r() or smth on its own. It should be an object's method, an
object responsible for that kind of job. So, you need the static
functions when you code such a class. The class can be abstract,
meaning that it cannot be used to create an instance, ou can just use
the abstract functions or of course inherit from it.
Furthermore, the class need not to be all static functioned, just a few
of the functions could be static. For example, you are going to create
an instance but that object needs to know, at creation time, some
attribute or smth. in that case, for good oop practice, you should not
use an external function, and if just the mentioned class is going to
use the static function, you should preserve the code in the mentioned
class.
Such discussions are into oop and once you begin to go completely OOP,
you will see the advantages, though it may be seeming ridiculous now.
Php4 was not OO, and being able to use a function as you mentioned may
not seem like a problem in the beginning, but once you begin using
other people's classes or using your classes a while later, you may not
be able to determine if a function was designed to run without
instantiation or not. Thats a problem for oop, as you have to know alot
about the class you are about to use, that harms the encapsulation.
So, it is of great importance for the class to use the function as it
was designed to be used like, as the reverse would steal your precious
time, making you try to understand what is going on by looking at the
code.
Navigation:
[Reply to this message]
|