Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #9041
| Message-ID | <3710226.RFm44XWl4p@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-04-12 11:58 +0200 |
| Subject | Re: Calling child class from parent class |
| Newsgroups | comp.lang.php |
| References | <1d7f9899-6d51-4d2d-b9a4-6e63ba979f26@googlegroups.com> <6f4737e3-b39b-4dd1-a765-f146c544f762@googlegroups.com> |
daveh@allheller.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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Calling child class from parent class daveh@allheller.net - 2013-04-11 12:48 -0700
Re: Calling child class from parent class Salvatore <sal@yojimbo.hack.invalid> - 2013-04-11 20:40 +0000
Re: Calling child class from parent class Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-11 23:15 +0200
Re: Calling child class from parent class daveh@allheller.net - 2013-04-11 17:11 -0700
Re: Calling child class from parent class Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-12 11:58 +0200
Re: Calling child class from parent class Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-11 22:49 -0400
csiph-web