Question: Consider the following Java code: public class Invoice { public void createInvoice ( ) { / / logic to create invoice } public void printInvoice
Consider the following Java code:
public class Invoice
public void createInvoice
logic to create invoice
public void printInvoice
logic to print invoice
public void emailInvoice
logic to email invoice
Which principle is being violated here, and how would you refactor the code?
Single Responsibility Principle SRP; split printInvoice and emailInvoice into separate classes.
Liskov Substitution Principle LSP; ensure subclasses can extend the behavior of Invoice.
OpenClosed Principle OCP; add new functionality to modify the behavior of createInvoice
Interface Segregation Principle ISP; divide the methods into multiple interfaces.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
