Question: Context: We've recently discussed Liskov Substitution Principle and the Interface Segregation Principle. Earlier this semester, we discussed the Open Closed, Single Responsibility and Dependency Inversion

 Context: We've recently discussed Liskov Substitution Principle and the Interface Segregation

Context: We've recently discussed Liskov Substitution Principle and the Interface Segregation Principle. Earlier this semester, we discussed the Open Closed, Single Responsibility and Dependency Inversion principles. , This assignment asks you to critique and irmprove code snippets using these principles. nd irmprove code snippets using Question 1: Consider the following production (shipped) code: Suppose a multi storied Building has an Elevator (In UML terms, the Building HAS Elevator). pu class Building private Elevator Elevator: private int floor: public Building) setFloor(15): Also suppose that while constructing the Elevator object, we need to give it the information about the Building object to access some functionalities of the Building class. Elevator new Elevator(); In this case, the speed of the Elevator depends on the number of floors of the Building. Therefore, when constructing the Elevator object, it must access functionalities of the Building object. (In UML terms the Elevator HAS Building). public int getFloor) return floor: public void setFloor(int floor) this.floor floor; //end of class building /class Elevator public class Elevator 2. Does the code violate (explain your answers) (30 pts) a. b. c. d. e. Single Responsibility Principle? Open Close Principle? Liskov Substitution Principle? Interface Segregation Principle? Dependency Inversion Principle? private Building building: private int Speed; public Elevator) There is a Circular Dependency in this code. the concept of interfaces, change the code so that the circular dependency is gone, but the desired functionality remains (42 3. buildingnew Building); setSpeed0 Using pts). public void setspeed) 4 Explain your answer to (3). (12 pts) (building.getFloor()-20) this.Speed 10 else t this.Speed 5 oublic int getSpeed) Speed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!