Mam taką encję:
public class Post
{
public int Id { get; internal set; }
public string Body { get; private set; }
public int LikeCount { get; private set; }
public bool IsAccepted { get; private set; }
public int TopicId { get; private set; }
public virtual Topic Topic { get; private set; }
public string AuthorId { get; private set; }
public virtual ApplicationUser Author { get; private set; }
public string AnonymousAuthorName { get; private set; }
public bool IsRemoved { get; private set; }
private Post()
{
}
public Post(string body, int topicId, string authorId, string anonymousAuthorName = null)
{
Body = body;
TopicId = topicId;
AuthorId = authorId;
AnonymousAuthorName = anonymousAuthorName;
}
public void Update(string body)
{
Body = body;
// Other editable properties here
}
public void Remove()
{
IsRemoved = true;
}
public void HasBeenAccepted()
{
IsAccepted = true;
}
public void AcceptanceHasBeenWithdrawn()
{
IsAccepted = false;
}
public void HasBeenLiked(string userId)
{
LikeCount++;
// TODO Create new Like object
}
public void LikeHasBeenWithdrawn(string userId)
{
LikeCount--;
// TODO Remove Like object
}
}
- Czy metody modelu nie robią za mało? Czy np. w metodzie
HasBeenLiked
nie powinienem sprawdzić, czy dany post nie został już polubiony przez danego użytkownika, czy może lepiej umieścić taką walidację w jakimś serwisie? - Gdybym chciał dodać, aby autor postu był powiadamiany o tym, że jego post został polubiony, to nowe powiadomienia powinienem tworzyć w metodzie
HasBeenLiked
, czy w jakimśNotifcationService
? - Czy w modelu
Topic
nie powinno być metody tworzącej nowe posty? Czy tworzenie postów po prostu przez konstruktor jest w porządku?