This is my first post. I try to convert the Abstract Factory class in c# to php. Of course, it does not work. Can you correct it for me, or give me a hint. Thanks.
--ngungo
Code:
<?php
class GUIFactory {
function GetFactory() {
if (TRUE) return new MacFactory();
else return new WinFactory();
}
public function CreateButton() {};
public function CreateLabel() {};
}
class WinFactory extends GUIFactory {
// Its there just to have the Classdiagram going
$btn = new WinButton();
$lbl = new WinLabel();
public override function CreateButton() {
return $btn;
}
public override function CreateLabel() {
return $lbl;
}
}
class MacFactory function GUIFactory {
// Its there just to have the Classdiagram going
$btn = new MacButton();
$lbl = new MacLabel();
public override function CreateButton() {
return $btn;
}
public override function CreateLabel() {
return $lbl;
}
}
abstract class Control {
public abstract function Show();
}
class WinButton extends Control {
public override function Show() {
echo "I'm a WinButton: ";
}
}
class MacButton extends Control {
public override function Show() {
echo "I'm an MacButton: ";
}
}
class WinLabel extends Control {
public override function Show() {
echo "I'm a WinLabel: ";
}
}
class MacLabel extends Control {
public override function Show() {
echo "I'm an MacLabel: ";
}
}
$factory = GUIFactory.GetFactory();
$button = factory.CreateButton();
echo $button->Show();
$label = factory.CreateLabel();
echo $label->Show();
?>