Design Patterns Interview Questions Hindi mein

Design Patterns कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Foundations of Design Patterns

1. Which category does the Builder pattern belong to?

  1. Behavioural
  2. Structural
  3. Creational
  4. Architectural
जवाब देखें

जवाब: Creational

Builder is about constructing objects step by step.

पाठ: What Design Patterns Are

2. What does "favour composition over inheritance" encourage?

  1. Building behaviour by combining objects instead of deep subclass hierarchies
  2. Avoiding interfaces entirely
  3. Putting all logic in one base class
  4. Using global variables for shared state
जवाब देखें

जवाब: Building behaviour by combining objects instead of deep subclass hierarchies

Composition keeps parts swappable and loosely coupled.

पाठ: The Principles Behind the Patterns

3. Which situation is most likely premature abstraction?

  1. A Builder for an object with many optional settings
  2. An Adapter wrapping an incompatible payment SDK
  3. A Strategy for three real shipping-cost rules
  4. An interface and factory for a class that has only one implementation and no planned variants
जवाब देखें

जवाब: An interface and factory for a class that has only one implementation and no planned variants

Abstractions should follow real variation.

पाठ: When Patterns Help and When They Hurt

Creational Patterns I: Factories and Builders

4. What is the main benefit of a factory for FileStorage?

  1. It makes storage faster
  2. Callers depend on the interface while one place decides the concrete class
  3. It removes the need for interfaces
  4. It guarantees only one storage instance exists
जवाब देखें

जवाब: Callers depend on the interface while one place decides the concrete class

The creation decision is centralised.

पाठ: Factory Method and Simple Factories

5. What problem does Abstract Factory specifically solve?

  1. Ensuring a class has one instance
  2. Creating related objects that must belong to the same family
  3. Adding behaviour to an object at runtime
  4. Iterating over a collection
जवाब देखें

जवाब: Creating related objects that must belong to the same family

It keeps product families consistent.

पाठ: Abstract Factory

6. In TypeScript, what often replaces a simple builder?

  1. A Visitor
  2. A Singleton
  3. An Observer
  4. An options object with defaults
जवाब देखें

जवाब: An options object with defaults

Object literals give named, optional parameters.

पाठ: Builder

Creational Patterns II and Dependency Injection

7. Why is Singleton often considered an anti-pattern?

  1. Global access hides dependencies and makes tests share state
  2. It always uses too much memory
  3. It cannot be used in TypeScript
  4. It creates a new object on every call
जवाब देखें

जवाब: Global access hides dependencies and makes tests share state

The global access point is the main problem.

पाठ: Singleton and Why It Is Often an Anti-Pattern

8. What is the risk of a shallow copy?

  1. It cannot copy strings
  2. It deletes the original
  3. Nested objects are shared, so changing them in one copy affects the other
  4. It always throws for nested data
जवाब देखें

जवाब: Nested objects are shared, so changing them in one copy affects the other

Only the top level is duplicated.

पाठ: Prototype and Cloning

9. What is the "composition root" in dependency injection?

  1. A global variable holding every object
  2. The base class of all services
  3. The single place, usually at startup, where concrete implementations are created and wired together
  4. The first database table created
जवाब देखें

जवाब: The single place, usually at startup, where concrete implementations are created and wired together

Wiring happens once, at the edge of the application.

पाठ: Dependency Injection as a Pattern

Structural Patterns I: Adapter, Decorator, Facade

10. When is an Adapter the right choice?

  1. When integrating a third-party API whose interface differs from the one your code expects
  2. When you need exactly one instance of a class
  3. When you want to undo user actions
  4. When you need to build an object step by step
जवाब देखें

जवाब: When integrating a third-party API whose interface differs from the one your code expects

Adapters translate between interfaces you do not control.

पाठ: Adapter

11. What distinguishes a Decorator from an Adapter?

  1. They are identical
  2. A Decorator always uses inheritance
  3. An Adapter adds caching
  4. A Decorator keeps the same interface and adds behaviour; an Adapter changes the interface
जवाब देखें

जवाब: A Decorator keeps the same interface and adds behaviour; an Adapter changes the interface

Decorators enhance; adapters translate.

पाठ: Decorator, Function Decorators and Middleware

12. What is a risk of a Facade that keeps growing?

  1. It stops compiling
  2. It turns into a god object that knows about everything
  3. It forces every caller to use inheritance
  4. It makes the subsystem faster
जवाब देखें

जवाब: It turns into a god object that knows about everything

Keep facades focused on a use case.

पाठ: Facade

Structural Patterns II: Proxy, Composite, Bridge and Flyweight

13. Which is an example of a virtual proxy?

  1. Converting one interface into another
  2. Delaying loading a large image or object until it is first used
  3. Notifying subscribers of changes
  4. Copying an existing object
जवाब देखें

जवाब: Delaying loading a large image or object until it is first used

Virtual proxies support lazy loading.

पाठ: Proxy

14. Which domain is a natural fit for Composite?

  1. Ensuring one database pool
  2. Retrying a failed HTTP request
  3. Choosing between payment providers
  4. A file system with files and folders
जवाब देखें

जवाब: A file system with files and folders

Composite models part-whole trees.

पाठ: Composite

15. What problem does Bridge address?

  1. A class explosion when two dimensions of variation are combined through inheritance
  2. Too many network calls
  3. Undoing user actions
  4. Iterating over a tree
जवाब देखें

जवाब: A class explosion when two dimensions of variation are combined through inheritance

Bridge lets each dimension vary independently.

पाठ: Bridge and Flyweight in Brief

Behavioural Patterns I: Strategy, Observer, Command

16. In TypeScript, what is often the simplest form of a Strategy?

  1. A deep inheritance hierarchy
  2. A Singleton class
  3. A function with a known signature, chosen from a map
  4. A global mutable variable
जवाब देखें

जवाब: A function with a known signature, chosen from a map

First-class functions replace many strategy classes.

पाठ: Strategy and Functions as Strategies

17. What is a common pitfall of the Observer pattern?

  1. It cannot have more than one observer
  2. It requires a database
  3. Listeners that are never removed, causing memory leaks or duplicate handling
  4. It forces synchronous network calls
जवाब देखें

जवाब: Listeners that are never removed, causing memory leaks or duplicate handling

Subscriptions need a lifecycle.

पाठ: Observer, Pub/Sub and Event Emitters

18. Why does Command make undo possible?

  1. Each action is an object that stores what is needed to execute and reverse it
  2. It deletes old data automatically
  3. It uses a Singleton history
  4. It prevents actions from running
जवाब देखें

जवाब: Each action is an object that stores what is needed to execute and reverse it

Encapsulated requests can be stored and reversed.

पाठ: Command

Behavioural Patterns II: State, Pipelines and Traversal

19. What is the main benefit of modelling an order as a state machine?

  1. It allows any state change at any time
  2. It makes the database faster
  3. It removes the need for tests
  4. Allowed transitions are explicit, so illegal ones are rejected
जवाब देखें

जवाब: Allowed transitions are explicit, so illegal ones are rejected

Explicit transitions replace scattered flags.

पाठ: State and State Machines

20. Web framework middleware is an everyday example of which pattern?

  1. Abstract Factory
  2. Chain of Responsibility
  3. Flyweight
  4. Prototype
जवाब देखें

जवाब: Chain of Responsibility

Each middleware handles the request or passes it on.

पाठ: Template Method and Chain of Responsibility

21. When is Visitor a poor fit?

  1. When you need to add new operations to stable node types
  2. When new node types are added frequently, because every visitor must change
  3. When walking a syntax tree
  4. When building a linter
जवाब देखें

जवाब: When new node types are added frequently, because every visitor must change

Visitor favours stable types and changing operations.

पाठ: Iterator and Visitor in Brief

Applying Patterns in Real Projects

22. What does the Unit of Work pattern do?

  1. Separates read and write databases
  2. Renders HTML views
  3. Ensures only one database connection exists
  4. Tracks changes in a business operation and commits them together
जवाब देखें

जवाब: Tracks changes in a business operation and commits them together

It groups changes into one atomic commit.

पाठ: Architectural Patterns Overview

23. Which is the best description of a god object?

  1. A class that accumulates too many unrelated responsibilities
  2. A class with exactly one method
  3. An immutable value object
  4. A small adapter around an SDK
जवाब देखें

जवाब: A class that accumulates too many unrelated responsibilities

Split it by responsibility.

पाठ: Anti-Patterns and Code Smells

24. What distinguishes Strategy from State?

  1. They solve unrelated problems and look nothing alike
  2. Strategy requires inheritance and State does not
  3. With Strategy the client chooses the algorithm; with State the object changes behaviour as its own state changes
  4. State is creational and Strategy is structural
जवाब देखें

जवाब: With Strategy the client chooses the algorithm; with State the object changes behaviour as its own state changes

Same structure, different intent.

पाठ: Patterns in Interviews and Code Review

25. Which is the best reason to introduce a pattern?

  1. It makes the codebase look more professional
  2. The pattern appears in a well-known book
  3. There is real, observed variation or change that the pattern makes easier to handle
  4. Every class should implement at least one pattern
जवाब देखें

जवाब: There is real, observed variation or change that the pattern makes easier to handle

Patterns earn their place by easing change.

पाठ: A Design Patterns Checklist

← कोर्स पर वापस जाएँ