Questions
15 of 24
1What are the SOLID principles? Explain each briefly.
2Explain the Single Responsibility Principle (SRP) with an example.
3Explain the Open/Closed Principle (OCP). How do you achieve it without modifying existing code?
4Explain the Liskov Substitution Principle (LSP). What happens if it's violated? (Square/Rectangle problem)
5Explain the Interface Segregation Principle (ISP). Why are fat interfaces bad?
6Explain the Dependency Inversion Principle (DIP). How does it relate to Dependency Injection?
7What is the difference between Aggregation and Composition?
8What is the Factory Pattern? How does it help in achieving OCP?
9What is the Abstract Factory Pattern? How does it differ from Factory Method?
10What is the Strategy Pattern? How does it replace complex conditional logic?
11What is the Observer Pattern? Where is it used in real life? (Event handling, Pub/Sub)
12What is the Decorator Pattern? How does it add functionality dynamically?
13What is a Singleton Pattern? What are the thread-safety concerns and how to handle them?
14What is an Anti-Pattern? Can you name a few? (God Object, Spaghetti Code, Golden Hammer)
15What is "Coupling" and "Cohesion"? Explain the relationship between them.
16What are Generics/Templates? How do they improve type safety and performance compared to casting?
17What is Type Erasure (Java) vs Reified Generics (C#)?
18What is Variance in Generics? (Covariance and Contravariance)
19What are Extension Methods (C#) or Default Methods (Java)? When should you use them?
20What is Reflection? How can it be used to break Encapsulation? What are the performance costs?
21What is the "Law of Demeter"? (Don't talk to strangers)
22Explain "Tell, Don't Ask" principle.
23What is the DRY principle? How does OOP help achieve it?
24What is the YAGNI principle?
15 / 24

What is "Coupling" and "Cohesion"? Explain the relationship between them.

Difficulty: 5/10
coupling, cohesion, module design

Coupling and Cohesion

Coupling describes how strongly one component depends on other components, while cohesion describes how closely the responsibilities within a component belong together. Good object-oriented architecture generally aims for high cohesion within modules and appropriately low coupling between modules. The goal is not zero coupling; some dependency is necessary. The architectural objective is to make dependencies intentional, stable and easy to change.

javascript
  1. 1

    High cohesion means a component has closely related responsibilities.

  2. 2

    Low coupling means fewer or more stable dependencies between components.

  3. 3

    High cohesion often makes components easier to understand and test.

  4. 4

    Low coupling makes changes less likely to ripple through the system.

  5. 5

    Use dependency inversion and composition to control coupling.

  6. 6

    Avoid optimizing for low coupling at the expense of a fragmented design.

Scenario Questions

0-2 years experience

  1. 1You have a `UserService` class that creates a `DatabaseConnection` directly inside each method. How would you change the code to reduce coupling?
  2. 2Two utility classes share many of the same helper methods. What does that tell you about their cohesion, and what would you do about it?
  3. 3If a module imports five other modules just to call a single function, what problems might arise and how would you address them?

2-5 years experience

  1. 1During a sprint you added a new feature that required changes in three services, and now an unrelated feature started failing. How would you investigate whether coupling is the root cause?
  2. 2You inherit a legacy class that handles authentication, logging, and data validation. How would you refactor it to improve cohesion, and what trade‑offs would you consider?
  3. 3When refactoring a payment processor you notice that every change forces a rebuild of the entire billing service. How would you reduce coupling while keeping performance acceptable?

5-8 years experience

  1. 1Design a microservice architecture for an e‑commerce platform. How do you decide the appropriate level of coupling between services, and what cohesion principles guide the service boundaries?
  2. 2A high‑cohesion component is tightly coupled to a synchronous logging library, causing latency spikes under load. How would you redesign to improve overall system performance?
  3. 3You need to split a monolithic cache manager into smaller components to scale horizontally. Discuss the coupling/cohesion trade‑offs and their impact on deployment and fault isolation.

8+ years experience

  1. 1Your organization plans to migrate a monolith to a plugin‑based platform. How would you evaluate existing modules' coupling and cohesion to prioritize the migration order?
  2. 2Multiple teams share a common library that has become a source of tight coupling and coordination overhead. What architectural strategies would you propose to improve cohesion and reduce coupling across teams?
  3. 3In a long‑term roadmap you must ensure new services stay loosely coupled yet highly cohesive as business requirements evolve. How would you set guidelines, governance, and metrics to enforce this at scale?

Follow-up Questions

  • Can you describe a concrete situation where tight coupling caused a regression?
  • How would you measure or assess cohesion in an existing codebase?
  • What are the practical downsides of enforcing extremely low coupling?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.