C# / .NET Compendium PLEN
.NET / C# / SOLID, Clean Code, DI

OOP and "Enterprise OOP"

OOP - the four pillars

Object-oriented programming rests on four principles that have already come up many times in our conversation (SOLID, inheritance modifiers, abstract/interface) - here I pull them together into one concise answer to the classic question "what is OOP".

1. Encapsulation

Hiding the internal state of an object and controlling access to it through a public API.

public class BankAccount
{
    private decimal _balance; // state is HIDDEN, not accessible from outside

    public decimal Balance => _balance; // read-only from outside

    public void Deposit(decimal amount)
    {
        if (amount <= 0) throw new ArgumentException("Amount must be positive");
        _balance += amount; // the only way to modify it - through a controlled method
    }
}

This goes back to the access modifiers we talked about - private/protected is the mechanism that physically enforces it.

2. Inheritance

A derived class inherits the behaviour and state of its base class - this is exactly virtual/override/abstract, which we already covered with the inheritance modifiers.

3. Polymorphism

The same interface/method behaves differently depending on the actual type of the object at runtime.

Animal[] animals = { new Dog(), new Cat() };
foreach (var a in animals) a.MakeSound(); // CALLS a different implementation, the SAME line of code

4. Abstraction

Hiding the complexity of the implementation behind a simple interface - IOrderRepository doesn't tell you how data is stored, only what you can do with it.


"Enterprise OOP" - a critical term, not a technical one

This is an important distinction: "Enterprise OOP" is not the formal name of yet another design pattern - it is a colloquial, slightly ironic term describing the pathological abuse of OOP/SOLID principles in large, corporate codebases (classically associated with Java EE/Spring from the 2000s, but the same happens in .NET) - where a simple task gets wrapped in a dozen layers of abstraction "just in case", without any real business need.

Where it comes from - a historical reference point

There is a famous, satirical open-source project called FizzBuzzEnterpriseEdition - an implementation of the trivial FizzBuzz interview task (print the numbers 1-100, "Fizz" for multiples of 3, "Buzz" for multiples of 5) blown up into dozens of classes, factories, strategies and interfaces - to show in practice what this anti-pattern looks like when you apply "all the best practices" without asking whether the problem calls for them.

An extended example - order discount calculation

This is a common interview task in a business version (not an abstract one like FizzBuzz): "calculate the order price after the discount - 10% off if the total exceeds 1000 PLN". Let's see what the same task looks like in the "Enterprise OOP" style and what a pragmatic solution looks like - this is good material to show in an interview that you understand the difference, not just that you can list patterns.

The "Enterprise OOP" version - 9 types to calculate one discount

// --- Kontrakty ---
public enum DiscountPolicyType { Standard, None }

public interface IDiscountPolicy
{
    decimal Apply(decimal amount);
}

public interface IDiscountPolicyFactory
{
    IDiscountPolicy Create(DiscountPolicyType type);
}

public interface IDiscountPolicyFactoryProvider
{
    IDiscountPolicyFactory GetFactory();
}

public interface IOrderDiscountOrchestrator
{
    decimal Calculate(OrderDiscountRequest request);
}

// --- Request DTO (because passing a plain "decimal" would be "inflexible") ---
public sealed class OrderDiscountRequest
{
    public decimal Amount { get; init; }
    public DiscountPolicyType PolicyType { get; init; }
}

// --- Implementacje polityk rabatowych ---
public sealed class StandardDiscountPolicy : IDiscountPolicy
{
    private const decimal Threshold = 1000m;
    private const decimal Rate = 0.10m;

    public decimal Apply(decimal amount)
        => amount >= Threshold ? amount - amount * Rate : amount;
}

public sealed class NoDiscountPolicy : IDiscountPolicy
{
    public decimal Apply(decimal amount) => amount;
}

// --- Fabryka polityk ---
public sealed class DiscountPolicyFactory : IDiscountPolicyFactory
{
    public IDiscountPolicy Create(DiscountPolicyType type) => type switch
    {
        DiscountPolicyType.Standard => new StandardDiscountPolicy(),
        _ => new NoDiscountPolicy()
    };
}

// --- Factory provider - because "what if there are MANY factories in the future?" ---
public sealed class DiscountPolicyFactoryProvider : IDiscountPolicyFactoryProvider
{
    public IDiscountPolicyFactory GetFactory() => new DiscountPolicyFactory();
}

// --- "Orchestrator" - because calling the policy directly would be too direct ---
public sealed class OrderDiscountOrchestrator : IOrderDiscountOrchestrator
{
    private readonly IDiscountPolicyFactoryProvider _provider;

    public OrderDiscountOrchestrator(IDiscountPolicyFactoryProvider provider)
        => _provider = provider;

    public decimal Calculate(OrderDiscountRequest request)
    {
        var factory = _provider.GetFactory();
        var policy = factory.Create(request.PolicyType);
        return policy.Apply(request.Amount);
    }
}

// --- DI registration - and you still have to wire ALL of this up ---
var services = new ServiceCollection(); // z Microsoft.Extensions.DependencyInjection
services.AddSingleton<IDiscountPolicyFactoryProvider, DiscountPolicyFactoryProvider>();
services.AddSingleton<IOrderDiscountOrchestrator, OrderDiscountOrchestrator>();
var serviceProvider = services.BuildServiceProvider(); // turns the registry into a working container

// --- Usage ---
var orchestrator = serviceProvider.GetRequiredService<IOrderDiscountOrchestrator>();
var total = orchestrator.Calculate(new OrderDiscountRequest
{
    Amount = 1200m,
    PolicyType = DiscountPolicyType.Standard
});

Let's count: 4 interfaces, 5 classes, 1 enum, 1 DTO, 2 DI registrations - 9 types to perform one comparison and one multiplication. Each of these elements "defends itself" on its own (Factory Pattern! Dependency Inversion! Single Responsibility!), but together they solve a problem that doesn't exist at all: nobody reported a need for multiple policy factories, or for multiple factory providers.

The pragmatic version - the same task

public static class OrderPricing
{
    private const decimal DiscountThreshold = 1000m;
    private const decimal DiscountRate = 0.10m;

    public static decimal CalculateTotal(decimal amount)
        => amount >= DiscountThreshold ? amount * (1 - DiscountRate) : amount;
}
var total = OrderPricing.CalculateTotal(1200m); // 1080

1 method, 2 constants. The same result, fully testable ([Theory]/[InlineData], as we discussed with xUnit), readable for anyone who opens this file for the first time.

When the "enterprise" version would actually make sense

To be fair - the extended version stops being a pathology when you really need: different discount policies selected at runtime based on configuration/customer segment, multiple independent factory providers (e.g. per region, per tenant in a multi-tenant SaaS), or when IDiscountPolicy has genuinely many implementations used interchangeably in production. The difference between good design and "Enterprise OOP" is not the presence of abstractions, but whether an abstraction answers an existing, confirmed need or only a hypothetical "what if someday".

How to recognise "Enterprise OOP" in practice - a checklist

Signal Example
An interface with one implementation, forever IOrderValidator with the only class OrderValidator, never swapped
A deep inheritance hierarchy "for the future" AbstractBaseServiceProviderFactoryManager
A design pattern applied without a problem it solves Strategy for logic that never changes
Intermediate layers that add no value A generic Repository over EF Core, which we discussed - GetAllAsync() returning what DbSet already gives
A "provider" of a provider of a factory As in the example above - IDiscountPolicyFactoryProvider
Class names longer than their contents AbstractSingletonProxyFactoryBean (a real Spring class, a classic joke in that world)

Why this matters in an SE III interview

This is effectively the closing of the SOLID topic we discussed at the very beginning - a good answer to "what do you think about SOLID" doesn't end with an enthusiastic list of principles, but shows restraint: knowing YAGNI ("You Aren't Gonna Need It") and KISS ("Keep It Simple") as counterweights. An SE III-level interviewer is often looking for exactly this - whether the candidate knows when to stop applying patterns, not just that they know them.

A good, concise answer in an interview: "OOP is encapsulation, inheritance, polymorphism and abstraction - the foundation SOLID stands on. 'Enterprise OOP' is an informal, critical term for abusing these principles - creating abstractions, factories and interfaces without a real, confirmed need, just 'because it's good practice'. A classic example is the satirical FizzBuzzEnterpriseEdition project. Good use of OOP is not maximising the number of patterns in the code, but solving a specific problem with the right, minimal level of abstraction - and you should be able to justify every additional layer with a concrete, existing need, not a hypothetical future."
Buy me a coffee