这是我考虑了一段时间的事情。我想将一组方法链接在一起,如下面的示例所示。
方法链的概念很简单,但我想要的是让我们所有的动物都通过同一个add
方法添加,那么我应该如何弄清楚我们在add
方法中添加的是什么类型的动物呢?
$zoo = new Zoo;
$lion = $zoo->lion->add('Lucas the lion');
$cockatoo = $zoo->cockatoo->add('Chris the cockatoo');
class Zoo {
function add($name) {
//How to figure out if the animal is a Lion or an Cockatoo?
}
}