0% found this document useful (0 votes)
7 views4 pages

Single Responsibility Principle Analysis

The document contains 3 questions about software design principles for a class assignment. Question 1 asks for an example of a class that is generic, extends an abstract class, and implements 2 interfaces. Question 2 asks about violating the single responsibility principle in a class diagram and redesigning it. Question 3 asks about violating and fixing the dependency inversion principle in a remote car control system.

Uploaded by

Baaru
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Single Responsibility Principle Analysis

The document contains 3 questions about software design principles for a class assignment. Question 1 asks for an example of a class that is generic, extends an abstract class, and implements 2 interfaces. Question 2 asks about violating the single responsibility principle in a class diagram and redesigning it. Question 3 asks about violating and fixing the dependency inversion principle in a remote car control system.

Uploaded by

Baaru
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Open book => lecture notes, handwritten notes, book; 90 minutes.

Question 1: [40 marks]


Give an example where a class at the same time (40 marks)
- Is a generic class
- Extends from an abstract class
- Implements 2 different interfaces

Question 2: [30 marks]


Given a design below (30 marks)

a. Explain why the design is violating the Single Responsibility Principle (15 marks)?
b. Redesign (by drawing a new diagram) to make it conform (satisfy) with the Single Responsibility
Principle (15 marks).
Question 3: [30 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.

public class Car {

public Car(){

/* ………..*/
}

public void lockCar() {

/* ………..*/

public void unLockCar() {

/* ………..*/

public class RemoteControl{

private Car car;

public RemoteControl(Car car){

[Link] = car;

public void clickOff() {

[Link]();

public void clickOn() {

[Link]();

a. Explain why the design is violating the Dependency Inversion Principle (15 marks)? (Hint:
define which class is the high-level module and which one is the low-level module)
b. This violation becomes clear when the system asks us to enable customers to re-use the
RemoteControl class to turn on and off other devices such as Motorbike.
- In this case, implement a Motorbike class and modify the RemoteControl class (without using
interface) so that it can control the Motorbike. (5 marks)
c. Rewrite the code to make it conform with the Dependency Inversion Principle (10 marks)

You might also like