Let's say we have few elements:
1) Simple PHP Class
<?php
class page {
function display() {
// Display widgets implementing widget interface
}
}
?>
2) Interface for Widget Classes
<?php
interface Widget {
function print();
}
?>
3) And few classes implementing the Widget interface
<?php
class Poll implements Widget {
function print() {
echo "I'm a poll";
}
}
class Form implements Widget {
function print() {
echo "I'm a form";
}
}
?>
What is the right way taking in mind SOLID PHP OOP logic to automatically run print() function in all classes implementing Widget interface? Let's assume all the files are already included.
Basically, whenever new class implementing Widget is created, it's response should be printed out in a page.
Maybe all my logic behind this is wrong?