我正在为我正在处理的 MVC 项目开发模型。我想知道是否最好为一项任务提供多个功能,或者为每种可以处理的方式提供一个功能。例如,最好有类似的东西:
public function get($identifiers = null, $limit = null, $offset = null)
{
if ($identifiers != null) {
if (is_array($identifiers)) {
$this->db->where($identifiers);
} else {
$this->db->where($this->_key, $identifiers);
$method = 'row'.($this->_return_array ? '_array' : '');
return $this->db->get($this->_table)->$method();
}
}
if ($limit != null) {
$this->db->limit($limit, $offset || null);
}
if (!count($this->db->ar_orderby)) {
$this->db->order_by($this->_order);
}
$method = 'result'.($this->_return_array ? '_array' : '');
return $this->db->get($this->_table)->$method();
}
处理多种情况或具有单独的功能,例如
get($id) {}
get_where($where) {}
get_all() {}
等等。