Question: Question 4 4 : Dependency Inversion Principle ( 2 5 ( 2 5 marks + 1 0 + 1 0 optional marks ) ) Dependency

Question 44: Dependency Inversion Principle (25(25 marks +10+10 optional marks))
Dependency Inversion Principle: High-level modules should not depend upon low level modules. Both should depend upon abstraction..
Suppose a car management system builds a new feature that enables customers to control cars remotely. In order to implement the new functionality, we create a Car class and a RemoteControl class. The Car class will allow users to lock the car and unlock the car. The RemoteControl class will let users click the remote device which is called the function lock and unlock the car. The following code is an implementation of the system.
package Dependency__Inversion01.01.Bad;
public class Car {{
private String color;
public Car((String color){){
this.color == color;
}}
public void lockCar(){(){
System.out.println("("locked")");
}}
public void unLockCar(){(){
System.out.println("("unlocked")");
}}
}}
package Dependency__Inversion01.01.Bad;
public class RemoteControl {{
private Car car;
public RemoteControl((Car car){){
this.car == car;
}}
public void ClickOff(){(){
car.lockCar()();
}}
public void clickOn(){(){
car.unLockCar()();
}}
}}
1/1/ Explain why the design is violating the Dependency Inversion class is the Principle (15(15marks)?()?(Hint:define which high-level module and which one is low-level module))
2/2/ This violation becomes clear when the class to turn system asks us to enable customer to re-use the RemoteControl on and off other devices such as Motorbike.
- In this case, implementa Motorbike class and modify the RemoteControl class
so that it can ((without using interface)) control the Motorbike. (5(5marks))
- Explain which principle would be violated here?(5(5 marks))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Explanation of Violation of Dependency Inversion Principle 15 marks The Dependency Inversion Principle states that highlevel modules should not depend ... View full answer

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 Programming Questions!