Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan

SOLID Principles and Code Smells

HardSQL & Data Manipulation00:00
Practice interviewer
In session
5 left
00:00

Your question is SOLID Principles and Code Smells. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

You're a Consultant at MATRIX Resources reviewing a client's invoicing service before recommending a refactor. Look at this class and identify which SOLID principles it violates.

class MySQLDatabase {
    void save(String table, long id, double value) {
        // writes directly to a MySQL connection
    }
}

interface InvoiceService {
    double process(Invoice invoice);
    void refund(Invoice invoice);
    void generateTaxReport(Invoice invoice);
}

class InvoiceProcessor implements InvoiceService {
    private MySQLDatabase db = new MySQLDatabase();
    private EmailClient emailClient = new EmailClient();
    private PdfRenderer pdfRenderer = new PdfRenderer();

    public double process(Invoice invoice) {
        double total = 0;
        if (invoice.getType() == "STANDARD") {
            total = invoice.getSubtotal() * 1.08;
        } else if (invoice.getType() == "CONTRACTOR") {
            total = invoice.getSubtotal() * 1.08 + 15.0;
        } else if (invoice.getType() == "NONPROFIT") {
            total = invoice.getSubtotal();
        }

        db.save("invoices", invoice.getId(), total);
        emailClient.send(invoice.getClientEmail(), "Your invoice total is " + total);
        pdfRenderer.render(invoice, total);

        return total;
    }

    public void refund(Invoice invoice) { /* ... */ }
    public void generateTaxReport(Invoice invoice) { /* ... */ }
}

class DiscountedInvoiceProcessor extends InvoiceProcessor {
    @Override
    public double process(Invoice invoice) {
        throw new UnsupportedOperationException("Discounted invoices use a different pipeline");
    }
}

Name each SOLID principle this violates, point to the exact line or method responsible, and explain the consequence in plain terms as if you were advising the client.