Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class Art {
- public static function getDescription(){
- if(!isset(static::$Description)) {throw new UnexpectedValueException(get_called_class() . ' must define a static Description property');}
- return static::$Description;
- }
- }
- interface Drawing{
- public function Draw();
- public function Delete();
- }
- abstract class Shape extends Art implements Drawing {
- abstract public function Draw();
- public function Delete(){echo "Deleted the " . static::getDescription() . "\n";}
- }
- class Square extends Shape {
- protected static $Description = "Square";
- public function Draw(){echo "Drawing something with four sides....\n";}
- }
- class Circle extends Shape {
- protected static $Description = "Circle";
- public function Draw(){echo "Drawing something round....\n";}
- }
- ?>
- <pre>
- <?php
- echo "Avialable Items to draw:\n";
- echo Square::getDescription() . ", " . Circle::getDescription() . "\n\n";
- $shape1 = new Square();
- $shape2 = new Circle();
- $shape1->Draw();
- $shape2->Draw();
- $shape1->Delete();
- $shape2->Delete();
- ?>
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement