Question: Question 1. (30 marks) Consider the following code base that followb a bad SOLID principle, State which principle it is violating and why. Fix the


Question 1. (30 marks) Consider the following code base that followb a bad SOLID principle, State which principle it is violating and why. Fix the design of the system so that it follows the stated principle. Submit the fixed code. Explain what did you change to fix the design to follow that principle. Given code: class Library \{ private ArrayListeBook> books; public Library0 \{ books = new ArrayList (); ) public void addBook(Book book) \{ books.add(book): ) public void removeBook(Book book) \& books remove(book); 1 public void printBooks() \{ for (Book book : books) f if (book.getType().equals("Novel")) \{ System.out.printin("Novel: " + book.getTite()); ) else if (book.getType0.equals("Textbook")) \{ System.out.println("Textbook: + book.getTite()): \} else if (book.getType() equals( Comic) ) \{ System.out.printin("Comic: " + book.getTitle()): ) \} \} class Book \{ private String title; private String type; public Book(String title, String type) \{ this .title = title; this.type = type; \} public String getTitle() \{ return title; \} public String getType() \{ return type; \} \} Fixed code (10 marks): Explanation (10 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
