What is the principle of Modularity in software engineering?
Modularity means breaking a software system into smaller, independent parts called modules. Each module handles a specific task, making the system easier to understand, develop, and maintain.
Click to reveal answer
beginner
Explain the DRY (Don't Repeat Yourself) principle.
DRY means avoiding duplication of code or logic. Instead of repeating the same code, you write it once and reuse it. This reduces errors and makes maintenance easier.
Click to reveal answer
intermediate
What does the Single Responsibility Principle (SRP) state?
SRP says that each part of a program should have only one reason to change. In other words, a module or class should focus on a single task or responsibility.
Click to reveal answer
beginner
Why is Testing important in software engineering?
Testing helps find and fix errors early. It ensures the software works as expected and improves quality and reliability before users see it.
Click to reveal answer
intermediate
Describe the Open/Closed Principle.
This principle means software entities like classes should be open for extension but closed for modification. You can add new features without changing existing code, reducing bugs.
Click to reveal answer
Which principle encourages breaking software into smaller parts?
ATesting
BDRY
COpen/Closed Principle
DModularity
✗ Incorrect
Modularity is about dividing software into smaller, manageable modules.
What does DRY stand for?
ADon't Repeat Yourself
BDo Repeat Yourself
CDebug Regularly Yourself
DDesign Right Yourself
✗ Incorrect
DRY means 'Don't Repeat Yourself' to avoid code duplication.
The Single Responsibility Principle means:
AA module should have many responsibilities
BModules should be open for modification
CA module should have only one reason to change
DModules should be tested once
✗ Incorrect
SRP states each module should focus on a single responsibility.
Why is testing done in software engineering?
ATo add new features
BTo find and fix errors early
CTo write more code
DTo increase software size
✗ Incorrect
Testing helps find and fix errors before software release.
The Open/Closed Principle means software should be:
AOpen for extension, closed for modification
BOpen for modification, closed for extension
CClosed for both extension and modification
DClosed for extension, open for modification
✗ Incorrect
It means software can be extended without changing existing code.
Explain the importance of modularity and how it helps in software development.
Think about how dividing a big task into smaller tasks helps.
You got /4 concepts.
Describe the DRY principle and why avoiding code duplication is beneficial.
Imagine fixing a bug in one place instead of many.
You got /4 concepts.
Practice
(1/5)
1. Which software engineering principle encourages writing code that does one thing and does it well?
easy
A. Open/Closed Principle
B. Don't Repeat Yourself (DRY)
C. Single Responsibility Principle (SRP)
D. Keep It Simple, Stupid (KISS)
Solution
Step 1: Understand the principle names
SRP means each module or class should have one responsibility or reason to change.
Step 2: Match the description to the principle
Writing code that does one thing well matches SRP.
Final Answer:
Single Responsibility Principle (SRP) -> Option C
Quick Check:
One responsibility = SRP [OK]
Hint: One job per module means SRP [OK]
Common Mistakes:
Confusing SRP with DRY which avoids repetition
Thinking KISS means single responsibility
Mixing Open/Closed with SRP
2. Which of the following is the correct description of the DRY principle?
easy
A. Avoid duplicating code or logic in multiple places
B. Keep code as simple as possible
C. Design software to be open for extension but closed for modification
D. Each class should have only one reason to change
Solution
Step 1: Recall DRY meaning
DRY stands for "Don't Repeat Yourself", meaning avoid code duplication.
Step 2: Match option to DRY
Avoid duplicating code or logic in multiple places says avoid duplicating code or logic, which matches DRY.
Final Answer:
Avoid duplicating code or logic in multiple places -> Option A
Quick Check:
DRY = no repetition [OK]
Hint: DRY means no repeated code [OK]
Common Mistakes:
Confusing DRY with Open/Closed principle
Mixing DRY with KISS which is about simplicity
Thinking DRY means single responsibility
3. Consider this code snippet applying the KISS principle:
B. The method is open for extension without changes
C. The code uses inheritance properly
D. The area method uses conditional logic to handle multiple shapes
Solution
Step 1: Understand Open/Closed Principle
It says software entities should be open for extension but closed for modification.
Step 2: Analyze the area method
The method uses if-else to handle different shapes, so adding a new shape requires modifying this method.
Final Answer:
The area method uses conditional logic to handle multiple shapes -> Option D
Quick Check:
Conditional logic breaks Open/Closed [OK]
Hint: If-else for types breaks Open/Closed [OK]
Common Mistakes:
Thinking inheritance is used properly here
Believing the class is closed for modification
Confusing open for extension with modifying code
5. You want to refactor this code to follow the Single Responsibility Principle (SRP):
class User:
def __init__(self, name, email):
self.name = name
self.email = email
def save_to_database(self):
# code to save user data
pass
def send_welcome_email(self):
# code to send email
pass
What is the best way to apply SRP here?
hard
A. Move save_to_database to a separate DatabaseHandler class
B. Keep all methods in User class since they relate to user
C. Combine both methods into one method for simplicity
D. Remove send_welcome_email method entirely
Solution
Step 1: Understand SRP
SRP says a class should have only one reason to change, so User should only hold user data.
Step 2: Identify responsibilities
Saving to database and sending emails are separate concerns from user data storage.
Step 3: Refactor accordingly
Move save_to_database to a DatabaseHandler class to separate concerns.
Final Answer:
Move save_to_database to a separate DatabaseHandler class -> Option A
Quick Check:
Separate responsibilities = SRP applied [OK]
Hint: One class, one reason to change means separate concerns [OK]
Common Mistakes:
Keeping all methods in one class breaks SRP
Combining methods increases complexity
Removing functionality instead of refactoring
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.