mercredi 21 octobre 2020

Design Pattern : Absolute beginner's struggle [closed]

It's my first approach to design patterns. I'm using a task from a book titled "Brief Java" by Cay Horstman p. 429. It's a simple invoice generator. Invoice class has-an Address and has-a LineItem that has-a Product. LineItem takes a Product and calculates amount.

It's fairly understandable to me. However another task tells to move the formatting to a separate class. As you can see format() is in 3 classes here and it makes sense to create a separate one. UML

And here is my problem as to how to do it. My first thought is to create an interface Formatter so then I can create HtmlFormatter, PaperFormatter etc. But how do I connect it to the Invoice? I'd be grateful for any tips. There aren't many tutorials on pattern design out there.

Aucun commentaire:

Enregistrer un commentaire