In what scenario an extension of a class is useful?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everybody :)

I'm really intrigued on something... In what real-world applications could
an extension of a class be really useful?

Let's say I have this code:

class foo {
  function hello_world($a) {
    echo 'foo hello world';
  }

  function bye_world() {
    echo 'foo bye world';
  }
}

class bar extends foo {
  function hello_world($a,$b) {
    echo 'bar hello world';
  }
}

Point 1: Why not just overwrite the hello_world method in the foo class in
the first place? Wouldn't that save code and possible incompatibility or
consistency issues between the code you've already written and between the
two classes ? (Assuming that you do some things based on the $a and $b
values).

Point 2: On the other hand, maybe I could apply different operations to both
(e.g.: return 1 in foo and 2 in bar), without breaking the basic
functionality already achieved in the foo class. (Maybe considering that I
want to apply an update or patch to an already existing application,
however, is this is the scenario, I should always fix the old code wherever
I invoke the foo class which returns us to point 1).

Point 3: Ok, maybe I don't want a specific class to be so huge and I
separate it into "pieces" of classes. But then again, wouldn't it be simpler
to just save some code and keeping only one file with the entire class?

Is it just that or do I miss something else? I'm not saying it is useless,
it sounds indeed fantastic to work with... but I just can't imagine in what
real-world cases this would be useful.

Greetings !

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux