Well I read that Anemic Domain Model is an anti-pattern and bad design, but I am a bit confused. I do understand the definition of this anti-pattern, but what is a good example of this? Let's say I have a model object called User, a data object called UserData, while the object UserData is a property of object User. A sample code is shown below:
class User extends Model{
protected $userdata;
protected $isloggedin;
protected $isadmin;
public function __construct($userid){
$this->userdata = $this->fetchData($userid);
// Other constructor code
}
protected function fetchData($userid){
return new UserData($userid);
}
public function __get($property){
if(!$this->data->get{$property}()) throw new DataNotFoundException("The data field is invalid.");
return $this->data->get{$property}();
}
public function isloggedin(){
return $this->isloggedin;
}
public function isAdmin(){
return $this->isadmin;
}
// More methods...
}
class UserData extends Data{
protected $uid;
protected $username;
protected $password;
protected $session;
protected $ip;
protected $birthday;
public function __construct($userid){
$db = Registry::get("Database");
$table = "users";
$fields = "*";
$whereclause = "uid = '{$userid}'";
$stmt = $db->select($table, $fields, $whereclause);
$row = $stmt->fetchObject();
$this->mapData($row);
// Other constructor code
}
public function getuid(){
return $this->uid;
}
public function getusername(){
return $this->username;
}
}
Is this considered an example of Anemic Domain Model anti-pattern? What if the data class UserData extends a base Data class that comes with a series of select, update method? Still anti-pattern? Just wondering...