jeudi 5 mars 2015

Software Design: Model method which model should belong

I am pretty sure this has been asked many times but I cannot think of a good search phrase to get some useful results, so I am going to ask again:


Lets say I have 3 model domains (apps), if expressed in django framework:



class User(Model):
pass

class Content(Model):
pass

class Comment(Model):
created_by = ForeignKey(User)
content = ForeignKey(Content)


If I want add a method to create a comment object, which Model should I implement the method in? I am in the dilemma between Content and User.


If it's user centric:



Class User(Model):
def add_comment(content, message):
....


If it's content centric:



Class Comment(Model):
def add_comment(user, message):
....


Is there a golden rule to decide? Or does it matter?


Aucun commentaire:

Enregistrer un commentaire