أسئلة القسم

تدرب على أسئلة المقابلات في هذا القسم. اكتب إجابتك، قم بتقييمها، أو اضغط على "عرض الإجابة" بعد التفكير.

What is SOLID? Can you elaborate on each SOLID acronym? سهل

A set of 5 object-oriented design principles:

Acronym Principle Meaning (simple)
S Single Responsibility Principle A class should have only one reason to change.
O Open/Closed Principle Open for extension, closed for modification.
L Liskov Substitution Principle Subclasses should be substitutable for base classes.
I Interface Segregation Principle Many small, specific interfaces are better than one large one.
D Dependency Inversion Principle Depend on abstractions, not on concrete implementations.
Name design patterns and principles you know and how they are utilized in .NET Framework. سهل
  • Creational Patterns:
    • Singleton: IConfiguration or IHttpClientFactory as singleton in DI.
    • Factory: DbContextFactory creates EF Core contexts.
  • Structural Patterns:
    • Adapter: Wrapping a third-party API in your own interface.
    • Decorator: Adding behavior to services without changing them (middleware).
  • Behavioral Patterns:
    • Strategy: PasswordHasher implementations or ILoggerProvider.
    • Command: MediatR library in .NET implements Command pattern for CQRS.
  • Principles:
    • SOLID, DRY, KISS, YAGNI
Implement the singleton, strategy, and command patterns. متوسط

Singleton:

public sealed class AppSettings {
    private static readonly Lazy<AppSettings> _instance =
        new Lazy<AppSettings>(() => new AppSettings());
    public static AppSettings Instance => _instance.Value;
    private AppSettings() {}
}

Strategy:

public interface IDiscountStrategy { decimal Apply(decimal price); }
public class NoDiscount : IDiscountStrategy { public decimal Apply(decimal p) => p; }
public class ChristmasDiscount : IDiscountStrategy { public decimal Apply(decimal p) => p * 0.8m; }

public class PriceCalculator {
    private readonly IDiscountStrategy _strategy;
    public PriceCalculator(IDiscountStrategy strategy) { _strategy = strategy; }
    public decimal Calculate(decimal price) => _strategy.Apply(price);
}

Command:

public interface ICommand { void Execute(); }
public class SaveOrderCommand : ICommand {
    public void Execute() { /* save order */ }
}
public class Invoker {
    public void Run(ICommand command) => command.Execute();
}
What’s the difference between Repository and Query Object patterns? متوسط
Aspect Repository Pattern Query Object Pattern
Purpose Abstracts persistence and CRUD operations. Encapsulates a single complex query.
Scope Whole aggregate or entity set. One-off or reusable query logic.
Usage IRepository<User> handles Add, Update, Delete, Get. UserByRoleQuery returns users by role.
What are the advantages and disadvantages of using a Repository pattern? متوسط

Advantages:

  • Centralized data access logic.
  • Easier to mock/test.
  • Decouples app from EF Core or other ORMs.

Disadvantages:

  • Can become bloated with many methods.
  • Sometimes duplicates EF Core features (extra layer).
  • Harder to optimize queries if overly generic.
What is CQRS, and in which scenarios may it be beneficial? صعب

CQRS = Command Query Responsibility Segregation. Separate write (commands) from read (queries) models.

Benefits:

  • Scalability (read and write can scale independently).
  • Clearer design when business rules differ between reads/writes.

Scenarios:

  • Complex domains with heavy read/write asymmetry.
  • Event sourcing or high performance read models.
What is the difference between an event and a command (like in CQRS)? صعب
Aspect Command Event
Intent Ask to do something (imperative). Notification something happened (past tense).
Responsibility Has a handler; expects action. May have multiple subscribers; no action guaranteed.
Timing Future action Already occurred
What is the Saga pattern? صعب

Orchestration for long-running or distributed transactions. Breaks a business process into a series of steps (local transactions) coordinated via messages. Handles compensating actions if a step fails.

What is Clean Architecture in .NET Core? صعب

An approach where business logic is independent of frameworks and UI.

Layers:

  • Domain (entities, core logic)
  • Application (use cases, interfaces)
  • Infrastructure (EF Core, external services)
  • Presentation (Web API, UI)

Dependency rule: outer layers depend inward.

Explain Monolithic vs Microservices architecture. صعب
Aspect Monolith Microservices
Deployment Single unit Independent services
Scaling Entire app scales Scale each service individually
Boundaries Shared database/code Each service has own DB, clear boundaries
Complexity Simple to start Higher operational complexity

When to choose:

  • Monolith for simple apps, low team size.
  • Microservices for large apps needing independent scaling/deployment.