I want to write an application that prints an document.
Which design would be better? Variant A:
class Document
{
public string Title { get; set; }
public string Author { get; set; }
public string Content { get; set; }
// ...
}
class DocumentPrinter
{
public void PrintDocument(Document document)
{
// ...
}
}
This would provide a dedicated DocumentPrinter-class which only does the printing. Or would it be better to add a Print()-method to the Document class itself, like here (Variant B):
public class Document
{
public string Title { get; set; }
public string Author { get; set; }
public string Content { get; set; }
public void Print()
{
// ...
}
}
What are the implicit trade-offs for both variantes? Which one is better in terms of maintainablity and architecture?
I would say Variant A is the better, because it will satisfy the " Single responsibility principle". But Variant B would be more intuitive to use.