Rihad wrote:
Now will you mentally copy and paste the above code several times, doing
the necessary text substitutions, what will you get? Three identical
copies of doSetColumn() in each class! And the real doSetColumn() is a
bit heavier than a one-liner. We come full circle.
I don't understand, which part(s) are you copying multiple times? Foo, FooBase, all the above...
if you are talking about having multiple Foo classes with one common FooBase class for each that
they all inherit then it would be simple, move soSetColumn() to the FooBase class.
Maybe this?
<?php
class FooPeer {
function BAR() {
return 'BAR';
}
function BAZ() {
return 'BAZ';
}
function XYZZY() {
return 'XYZZY';
}
}
class BaseFoo {
function setBar($colname, $value) {
echo "BaseFoo::setBar({$colname}, {$value});\n";
}
function setBaz($colname, $value) {
echo "BaseFoo::setBaz({$colname}, {$value});\n";
}
function setXyzzy($colname, $value) {
echo "BaseFoo::setXyzzy({$colname}, {$value});\n";
}
function doSetColumn($colname, $value, $col_mutator) {
BaseFoo::$col_mutator($colname, $value);
}
}
class Foo1 extends BaseFoo {
function setBar($value) {
$this->doSetColumn(FooPeer::BAR(), $value, __FUNCTION__);
}
function setBaz($value) {
$this->doSetColumn(FooPeer::BAZ(), $value, __FUNCTION__);
}
function setXyzzy($value) {
$this->doSetColumn(FooPeer::XYZZY(), $value, __FUNCTION__);
}
}
class Foo2 extends BaseFoo {
function setBar($value) {
$this->doSetColumn(FooPeer::BAR(), $value, __FUNCTION__);
}
function setBaz($value) {
$this->doSetColumn(FooPeer::BAZ(), $value, __FUNCTION__);
}
function setXyzzy($value) {
$this->doSetColumn(FooPeer::XYZZY(), $value, __FUNCTION__);
}
}
echo "<pre>";
$Foo1 = new Foo1();
$Foo1->setBar('my value for bar');
$Foo1->setBaz('my value for baz');
$Foo1->setXyzzy('my value for xyzzy');
$Foo2 = new Foo2();
$Foo2->setBar('my value for bar');
$Foo2->setBaz('my value for baz');
$Foo2->setXyzzy('my value for xyzzy');
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php