programming
beginner
10 sample questions
Modular Programming MCQ Practice Test
Breaking down large programs into smaller, manageable modules.
Using encapsulation to hide unnecessary details.
Q1. You're developing a program to process images. One module handles image resizing, another handles image filtering (like applying a sepia tone), and a third handles saving the processed image. Which principle of modular programming BEST describes this organization?
-
A. Abstraction
-
B. Encapsulation
-
C. Separation of Concerns ✓
-
D. Inheritance
Explanation: Separation of Concerns is the principle of dividing a program into independent modules, each responsible for a specific task or aspect of the program's functionality. In this example, each module has a clear, separate responsibility. While abstraction and encapsulation are related, they don't directly address the core organizational principle at play here.
Q2. In a modular programming approach, which of the following design patterns ensures that each module is loosely coupled and can be developed, tested, and maintained independently, without affecting other modules?
-
A. Model-View-Controller (MVC)
-
B. Model-View-Presenter (MVP)
-
C. Domain-Driven Design (DDD)
-
D. Event-Driven Architecture (EDA) ✓
Explanation: Event-Driven Architecture (EDA) is a design pattern that enables loose coupling between modules by using events to communicate between them. This allows each module to be developed, tested, and maintained independently, without affecting other modules.
Q3. In a modular programming approach, which of the following is an advantage of using a 'separate compilation unit'?
-
A. It allows for faster compilation of the entire program
-
B. It enables easier modification and maintenance of individual components ✓
-
C. It reduces the overall size of the program executable
-
D. It prevents the use of third-party libraries
Explanation: In modular programming, a separate compilation unit is a self-contained module that can be compiled independently of other modules. This allows for easier modification and maintenance of individual components, as changes to one module do not affect other modules.
Q4. In a modular programming approach, what is the primary benefit of using a <strong>Interface Segregation Principle</strong> (ISP) in a system with multiple, independent modules that communicate with each other through APIs?
-
A. It allows for a single, monolithic API that all modules can use
-
B. It enables each module to define its own, custom API without affecting other modules ✓
-
C. It reduces the complexity of the system by minimizing the number of APIs
-
D. It increases the coupling between modules, making them harder to maintain
Explanation: The Interface Segregation Principle (ISP) is a design principle that suggests each module should have a small, focused interface that is tailored to its specific needs, rather than a large, general-purpose interface that may be used by multiple modules. This allows each module to define its own API without affecting other modules, promoting loose coupling and improved maintainability.
Q5. In a modular programming approach, which of the following is an advantage of using a “Module Interface” in a “Module A” that depends on a “Module B”?
-
A. The Module Interface allows Module A to be compiled independently of Module B
-
B. The Module Interface enables Module A to be reused in other projects without modifying its dependencies
-
C. The Module Interface reduces the coupling between Module A and Module B by hiding their internal implementation details ✓
-
D. The Module Interface eliminates the need for Module A to import any classes or functions from Module B
Explanation: A Module Interface is a design pattern that allows a module to expose a well-defined interface to its dependencies, while hiding its internal implementation details. This reduces coupling between modules, making it easier to modify or replace one module without affecting others.
Q6. In a microservices architecture, what is a key advantage of using a dependency injection container to manage service dependencies?
-
A. It increases the coupling between services by requiring them to directly reference each other's dependencies.
-
B. It simplifies testing by allowing dependencies to be easily mocked or stubbed. ✓
-
C. It promotes a monolithic architecture by tightly coupling services through a centralized dependency management system.
-
D. It makes it more difficult to refactor services as changes to dependencies require modifications across multiple services.
Explanation: Dependency injection containers centralize the management of dependencies, making it easier to replace real dependencies with mock objects for testing purposes. This reduces coupling and improves testability in a microservices architecture.
Q7. What is the primary advantage of a Dependency Injection (DI) container in a large application?
-
A. Reduced coupling: modules receive their dependencies from outside, so they are easier to swap, test, and reuse independently ✓
-
B. It compiles the code faster
-
C. It removes the need for any dependencies
-
D. It makes the user interface prettier
Explanation: DI's core benefit is decoupling: components depend on abstractions whose implementations are injected, improving testability (mocks), reusability, and maintainability — scalability via easy swapping is a downstream consequence.
Q8. In a modular programming approach, which of the following is an advantage of using a Service-Oriented Architecture (SOA) in a microservices-based system?
-
A. Improved scalability through loose coupling of services ✓
-
B. Reduced coupling between services through synchronous communication
-
C. Enhanced fault tolerance through distributed transactions
-
D. Simplified debugging through centralized logging
Explanation: In a Service-Oriented Architecture (SOA), services are designed to be loosely coupled, allowing for improved scalability and flexibility. This is because services can be developed, deployed, and scaled independently, reducing the risk of cascading failures and improving overall system resilience.
Q9. In a modular programming approach, what is the primary benefit of using a “facade” pattern in a cross-cutting concern like logging?
-
A. Improved code reusability through inheritance
-
B. Enhanced maintainability by reducing coupling ✓
-
C. Simplified debugging through centralized logging configuration
-
D. Increased performance through caching
Explanation: The facade pattern in modular programming helps to reduce coupling between different modules by providing a single interface for a cross-cutting concern like logging. This improves maintainability by making it easier to change or replace the logging module without affecting other parts of the system.
Q10. In a modular programming approach, which of the following design patterns is used to manage dependencies between modules, ensuring that a module's implementation details are not exposed to other modules?
-
A. The Bridge pattern
-
B. The Dependency Inversion Principle (DIP) ✓
-
C. The Adapter pattern
-
D. The Facade pattern
Explanation: The Dependency Inversion Principle (DIP) is a design pattern that encourages decoupling of modules by introducing abstractions and interfaces, allowing for more flexibility and maintainability in software development.
That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.
Sign Up Free