In method main I have String page which contain some big text, and such code:
List<String> wordsList = getWordsList(page);
System.out.println("Total number of words is: " + wordsList.size());
Map<String, Long> wordsSortedMap = getWordsSortedMap(wordsList);
wordsSortedMap.forEach((k, v) -> System.out.println(v + "\t" + k));
As you see I juct use util methods getWordsList and getWordsSortedMap to construct needed data and print it out to console.
So, How to make the application extensible? To be able to add new types of reports without changing the existing code.
For example, the input data is always this page variable. And for example in the main could be this:
ReportsExecutor.printReportOne(page);
ReportsExecutor.printReportTwo(page);
or this:
ReportOne reportOne = new ReportOne(page);
ReportTwo reportTwo = new ReportTwo(page);
reportOne.execute();
reportTwo.execute();
Is there a suitable design pattern or any OOP best practices for this case?
Aucun commentaire:
Enregistrer un commentaire