Software Engineering Software Engineering 2 — Questions and Answers
Question 1: Which design pattern ensures only one instance of a class exists throughout an application?
- Factory
- Singleton (Correct answer)
- Observer
- Decorator
Correct answer: Singleton
The Singleton pattern restricts instantiation of a class to a single object and provides global access to that instance.
Question 2: In CI/CD pipelines, what does 'continuous delivery' mean?
- Code is automatically deployed to production on every commit
- Code is automatically tested and kept in a deployable state (Correct answer)
- Developers integrate code multiple times per day
- Infrastructure is provisioned automatically
Correct answer: Code is automatically tested and kept in a deployable state
Continuous delivery ensures code is always in a releasable state by automating build, test, and staging, but deployment to production is triggered manually.
Question 3: What is 'technical debt' in software engineering?
- Licensing costs for third-party software
- The cost of delayed features due to budget cuts
- The implied cost of rework caused by choosing quick solutions over better approaches (Correct answer)
- Money owed to contractors for development work
Correct answer: The implied cost of rework caused by choosing quick solutions over better approaches
Technical debt refers to the future rework required when shortcuts or suboptimal solutions are chosen to speed up delivery.
Question 4: Which SOLID principle states that a class should have only one reason to change?
- Open/Closed Principle
- Liskov Substitution Principle
- Single Responsibility Principle (Correct answer)
- Interface Segregation Principle
Correct answer: Single Responsibility Principle
The Single Responsibility Principle (SRP) states that a class should have only one job or responsibility.
Question 5: What is the primary purpose of a code review?
- To measure developer performance for HR evaluations
- To catch defects, ensure code quality, and share knowledge (Correct answer)
- To track how many lines of code each developer writes
- To enforce coding style rules automatically
Correct answer: To catch defects, ensure code quality, and share knowledge
Code reviews improve software quality by identifying bugs and design issues early, and they help spread knowledge across the team.
Question 6: In software testing, what distinguishes a 'stub' from a 'mock'?
- Stubs replace entire modules; mocks replace individual functions
- Stubs provide canned responses; mocks verify interactions were called correctly (Correct answer)
- Stubs are used in integration tests; mocks are used in unit tests
- There is no meaningful difference between stubs and mocks
Correct answer: Stubs provide canned responses; mocks verify interactions were called correctly
Stubs return predefined data to satisfy dependencies, while mocks also assert that specific methods were called with expected arguments.
Question 7: What does 'idempotency' mean in the context of API design?
- The API returns results sorted alphabetically
- Calling the same operation multiple times produces the same result as calling it once (Correct answer)
- The API supports multiple authentication methods
- Responses are cached for a fixed time period
Correct answer: Calling the same operation multiple times produces the same result as calling it once
An idempotent operation produces the same state regardless of how many times it is applied, making retries safe.
Which design pattern ensures only one instance of a class exists throughout an application?