
.NET Design Patterns
Singleton, Factory, Builder, Strategy, Decorator, Repository, Unit of Work, SOLID
1What is the main issue with the Singleton pattern in modern .NET with Dependency Injection?
What is the main issue with the Singleton pattern in modern .NET with Dependency Injection?
Resposta
The classic Singleton pattern (static instance) conflicts with dependency injection because it creates tight coupling and makes testing difficult. In modern .NET, it's better to use the 'Singleton' service lifetime via DI (services.AddSingleton), which provides the same single-instance guarantee while enabling injection, mocking, and testability. Static Singleton bypasses the DI container and creates hidden dependencies.
2In the Factory Method pattern, what is the difference between Factory Method and Abstract Factory in .NET?
In the Factory Method pattern, what is the difference between Factory Method and Abstract Factory in .NET?
Resposta
Factory Method defines a virtual method to create a single type of object (e.g., CreateLogger), allowing subclasses to decide which concrete class to instantiate. Abstract Factory defines an interface for creating families of related objects (e.g., IUIFactory with CreateButton, CreateTextBox), allowing multiple coherent products to be created together. Factory Method focuses on a single product with polymorphism, Abstract Factory manages multiple products from the same family.
3What is the main advantage of the Builder pattern in .NET for creating complex objects with many optional parameters?
What is the main advantage of the Builder pattern in .NET for creating complex objects with many optional parameters?
Resposta
The Builder pattern avoids telescoping constructors (multiple overloads with different parameter combinations) by providing a fluent interface to build the object step by step. It allows creating complex objects with optional parameters in a readable and maintainable way, unlike constructors with 10+ parameters. In modern C#, init properties and records can replace Builder for simple cases, but Builder remains useful for complex validation or multi-step construction.
What is the Single Responsibility Principle (SRP) in SOLID and how to apply it in .NET?
What is the Open/Closed Principle (OCP) in SOLID and how to implement it with interfaces in .NET?
+21 perguntas de entrevista
Outros temas de entrevista .NET
C# Basics
LINQ & Delegates
C# Language Essentials
ASP.NET Core Fundamentals
ASP.NET Core Request Lifecycle
Configuration & Settings
Application Lifecycle
Dependency Injection
Entity Framework Core
Minimal APIs
Web API Development
Async in ASP.NET Core
Authentication & Authorization
HttpClient & Networking
JSON Serialization
Entity Framework Core Advanced
C# Advanced Features
Clean Architecture
Logging, Monitoring & Observability
Unit Testing & xUnit
Integration Testing
Docker & Containerization
NuGet Package Management
Memory Management & GC
Reactive Programming
Async/await & Patterns
Performance Optimization
Security & Best Practices
SignalR & Real-time
Microservices Architecture
Domine .NET para sua proxima entrevista
Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.
Comece gratis