Architecture & Design Patterns Flashcards

MVC, Service Layer Singleton, Factory, Middleware Pattern Dependency Injection Layered Architecture Folder Structures (48 cards)

1
Q

What is the MVC pattern?

A

MVC (Model-View-Controller) is a design pattern that separates an application into three components: Model (data), View (UI), and Controller (logic).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Service Layer?

A

A service layer encapsulates business logic, decoupling it from controllers and models for better modularity and testability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the Singleton pattern?

A

Singleton ensures a class has only one instance and provides a global point of access to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Factory pattern?

A

Factory is a creational pattern that provides an interface for creating objects without specifying their exact class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Middleware pattern?

A

Middleware is a pattern used in web frameworks like Express where functions are chained to process requests/responses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Dependency Injection?

A

Dependency Injection is a technique where dependencies are passed into a component rather than being created inside it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Layered Architecture?

A

Layered Architecture organizes an application into layers like presentation, business, and data, each with specific responsibilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are common folder structures in Node.js?

A

Typical folder structures include folders for routes, controllers, services, models, middleware, and config.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an advantage of MVC?

A

MVC separates concerns, making the application easier to manage, scale, and test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a disadvantage of MVC?

A

It can lead to bloated controllers and complex data flow if not implemented carefully.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an advantage of the service layer?

A

Improves modularity by isolating business logic, making testing and reusability easier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a disadvantage of the Singleton pattern?

A

It introduces global state which can make testing and debugging harder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a best practice for using factories?

A

Use factories when object creation logic is complex or dependent on dynamic input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a use case for the Singleton pattern?

A

Database connections or logging instances where only one instance should exist.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a use case for middleware?

A

Authentication, logging, and input validation in Express.js applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the impact of Dependency Injection on system design?

A

It promotes loosely coupled and testable components, making systems more flexible and maintainable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Give an example of layered architecture.

A

An Express app with separate folders for API (routes/controllers), services (business logic), and models (database).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are architectural implications of using Singleton?

A

Can make system state shared globally, reducing flexibility and increasing risk of side effects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a performance benefit of the Singleton pattern?

A

Prevents repeated instantiation of heavy objects like DB clients, improving resource efficiency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a debugging challenge with the Singleton pattern?

A

Hidden global state can make it hard to track issues or reproduce bugs.

21
Q

What is a real-world tradeoff with MVC?

A

Easy to get started but can become rigid or confusing with complex apps if layering isn’t well-maintained.

22
Q

What is a potential gotcha with Dependency Injection?

A

Improper use can lead to overengineering or excessive indirection, making code harder to follow.

23
Q

What is a common interview question about design patterns?

A

Explain the difference between Singleton and Factory patterns and when you’d use them.

24
Q

What is a best practice for folder structures?

A

Organize by feature/module rather than type (e.g., users/ with its own routes, controllers, models).

25
What is the role of controllers in MVC?
Controllers handle HTTP requests, interact with services/models, and return responses to the client.
26
What is the role of services in a service layer?
Services contain business logic and can be reused across different controllers or apps.
27
How does middleware improve fault tolerance?
Centralized middleware can catch and handle errors globally, improving app stability.
28
What is a disadvantage of layered architecture?
May introduce complexity and performance overhead if overused for small apps.
29
What is a use case for factory pattern in Node.js?
Creating database adapters or loggers based on environment or config at runtime.
30
How does dependency injection improve testability?
Allows mocking of dependencies during tests, making unit testing easier.
31
What is a folder structure gotcha in Node.js apps?
Over-nesting or inconsistent structure can confuse developers and hinder maintainability.
32
What is a monitoring tip for layered architecture?
Log entry/exit points in each layer to trace request flow and pinpoint issues.
33
What’s a common folder structure in Express apps?
/routes, /controllers, /services, /models, /middlewares, /utils, /config
34
What is a common interview question on Dependency Injection?
How does dependency injection differ from service locator pattern?
35
What is the impact of design patterns on scalability?
Well-applied patterns create modular, scalable architectures that are easier to maintain and extend.
36
What’s a tradeoff when using the service layer?
Adds complexity for small apps but pays off in large, complex systems with reusable logic.
37
What’s a benefit of centralized middleware?
Reduces duplication and keeps concerns like logging or validation separate from business logic.
38
What’s a risk of improper Singleton usage?
Can accidentally introduce shared mutable state across requests, causing race conditions.
39
How does MVC affect performance?
Adds abstraction layers, but proper separation improves long-term performance and maintainability.
40
What is an example of dependency injection in JavaScript?
Passing a logger or DB client into a service class constructor instead of creating it inside.
41
How does middleware chaining work in Express?
Each middleware calls `next()` to pass control to the next function in the stack.
42
What’s a debugging tip for layered architecture?
Log each layer’s input and output, and use error-handling middleware for global issues.
43
What’s the benefit of using factory pattern with configuration?
Allows easy switching between implementations (e.g., using Mongo or PostgreSQL) at runtime.
44
What’s a disadvantage of deeply nested folder structures?
Can slow down onboarding and make file navigation cumbersome.
45
What is an Express middleware function signature?
`(req, res, next)` – where `next` passes control to the next middleware.
46
How does DI help in testing services?
You can inject mock dependencies to isolate and test service behavior without side effects.
47
How does Factory pattern support the Open/Closed Principle?
By encapsulating object creation, you can add new types without modifying existing code.
48
What’s the impact of folder structure on system design?
A well-thought structure improves clarity, maintainability, and team collaboration.