I use yii2 and find that it's active record is very convenient.
But sometimes I find that we always put logic functions in active record which I think should belongs to domain.
And I have looked up some books, most of them suggest using data mapper to mapping database record to domain.
Although it is a good way to split domain and data, I don't want to waste active record feature from yii2.
I think we can make a domain extend from active record so that the database operations will in domain's parent class active record, and business logic operations will in domain:
class UserModel extends ActiveRecord{
// do database operations
}
class UserDomain extends UserModel{
// do domain's logic
}
I don't know is this design great? Please tell me your suggests.
Aucun commentaire:
Enregistrer un commentaire