用观察者的PHP对象组成?

Excuse me if my terminology seems incorrect... (because it probably is)

Say i am using composition and my higher-level objects are something like:

abstract child
{
    /* array of Activity objects */
    public $activities;

    abstract function punish() {}
}

favoriteChild extends child
{
    function punish() {
        // Have a talk
    }
}

redHeadedStepChild extends child
{
    function punish() {
        // Beat with wrench
    }
}

Now let's say that $activities is composed of more objects, -one of which being StealingCookiesFromJar.

How can I call the concrete child method punish from inside the StealingCookiesFromJar object? (I'm not familiar with observers... is that what I should be learning here?)

You need a concrete child inside StealingCookiesFromJar object. Create it or pass it into a method

 class StealingCookiesFromJar{
    function doSomething(){
      $child = new redHeadedStepChild();
      $child->punish();
     }
  }

or

 class StealingCookiesFromJar{
    function doSomething(redHeadedStepChild $child){
       $child->punish();
    }
  }