我正在爲我正在開發的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() {}
等。
我認爲第二個版本是更好,如果你想要的東西,如「乾淨的代碼」 – Philipp 2013-03-27 21:36:15