Architecture & Design Patterns Flashcards
MVC, Service Layer Singleton, Factory, Middleware Pattern Dependency Injection Layered Architecture Folder Structures (48 cards)
What is the MVC pattern?
MVC (Model-View-Controller) is a design pattern that separates an application into three components: Model (data), View (UI), and Controller (logic).
What is a Service Layer?
A service layer encapsulates business logic, decoupling it from controllers and models for better modularity and testability.
What is the Singleton pattern?
Singleton ensures a class has only one instance and provides a global point of access to it.
What is the Factory pattern?
Factory is a creational pattern that provides an interface for creating objects without specifying their exact class.
What is the Middleware pattern?
Middleware is a pattern used in web frameworks like Express where functions are chained to process requests/responses.
What is Dependency Injection?
Dependency Injection is a technique where dependencies are passed into a component rather than being created inside it.
What is Layered Architecture?
Layered Architecture organizes an application into layers like presentation, business, and data, each with specific responsibilities.
What are common folder structures in Node.js?
Typical folder structures include folders for routes, controllers, services, models, middleware, and config.
What is an advantage of MVC?
MVC separates concerns, making the application easier to manage, scale, and test.
What is a disadvantage of MVC?
It can lead to bloated controllers and complex data flow if not implemented carefully.
What is an advantage of the service layer?
Improves modularity by isolating business logic, making testing and reusability easier.
What is a disadvantage of the Singleton pattern?
It introduces global state which can make testing and debugging harder.
What is a best practice for using factories?
Use factories when object creation logic is complex or dependent on dynamic input.
What is a use case for the Singleton pattern?
Database connections or logging instances where only one instance should exist.
What is a use case for middleware?
Authentication, logging, and input validation in Express.js applications.
What is the impact of Dependency Injection on system design?
It promotes loosely coupled and testable components, making systems more flexible and maintainable.
Give an example of layered architecture.
An Express app with separate folders for API (routes/controllers), services (business logic), and models (database).
What are architectural implications of using Singleton?
Can make system state shared globally, reducing flexibility and increasing risk of side effects.
What is a performance benefit of the Singleton pattern?
Prevents repeated instantiation of heavy objects like DB clients, improving resource efficiency.
What is a debugging challenge with the Singleton pattern?
Hidden global state can make it hard to track issues or reproduce bugs.
What is a real-world tradeoff with MVC?
Easy to get started but can become rigid or confusing with complex apps if layering isn’t well-maintained.
What is a potential gotcha with Dependency Injection?
Improper use can lead to overengineering or excessive indirection, making code harder to follow.
What is a common interview question about design patterns?
Explain the difference between Singleton and Factory patterns and when you’d use them.
What is a best practice for folder structures?
Organize by feature/module rather than type (e.g., users/ with its own routes, controllers, models).