PHPだけど、
class array_formatter{
    function format_array(&$array){
        if(!count($array)) return $this->format_empty();

        $html  = $this->format_header($array);
        foreach($array as $key => $value){
            $html .= $this->format_item($key, $value);
        }
        $html .= $this->format_footer($array);
        return $html;
    }
    function format_empty(){
    }
    function format_header(&$array){
    }
    function format_footer(&$array){
    }
    function format_item($key, $value){
    }
}

こんな感じのクラスを継承して使いまくってる。