FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Calling child class from parent class
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Calling child class from parent class [message #181098 is a reply to message #181096] Fri, 12 April 2013 09:58 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
daveh(at)allheller(dot)net wrote:

> Actually I combined the two classes into one

Probably not a good idea.

> (I don't understand why the original programmer did not do that in the
> first place

AIUI, it does make sense to have two classes, one whose instance holds
metadata about other objects and the other one whose instances hold the
payload. This is called /aggregation/, or, if it implies ownership,
/composition/.

The design error apparently made here is to have one class inherit from the
other (“is-a”, not “has-a” relationship) and, instead of passing the
(reference to the) instance to the register() method, have the instance
created by that method, which I think violates the Law of Demeter (the other
class's instance does not exist until register() is called, therefore it
would not be a “direct component object” – CMIIW). That is,

$dir = new GNP_DIRECTORY();
$gtcm = new GTCM_GNP($dat_file, $server, $port);
$dir->register($name, $rule, $gtcm);

would be cleaner.

> perhaps because it was written for php version 4.0.6

Highly unlikely. There were no visibility specifiers in PHP 4:

<http://www.php.net/manual/en/oop5.intro.php>

> and also made heavy use of superglobals in his code)

If they are *superglobals* instead of *simple* globals, there is nothing
wrong with that. However, there might be reached a point where you would
want to cache the superglobal value, for example in a local variable, in
favor of DRY.

> And actually the names are not cryptic IF read in the context
> of what the code does. It actually manipulates a gnp_directory and
> gtcm_gnp objects.

“gtcm_gnp” still looks cryptic to me. You have to *explain* to me – that
is, another developer – what it *is* (I *have* to read the documentation),
and that is the problem with it. (What does it mean, anyway?)

> I probably will change the case of the classes however,
> because "shouting" can be annoying!

That is _not_ the reason why you should do it. You need to distinguish
between programming and natural languages.

Please learn to quote and get a real name.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Calling a php file from another on apache server
Next Topic: Re: eine PHP mit video faehigkeit
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 22:45:16 GMT 2024

Total time taken to generate the page: 0.04974 seconds