Skip to main content

Anti-Pattern: The "God Method" (Importer Edition)

🔴 The Problem

A single method that handles File I/O, Parsing, Data Validation, Business Logic and Database Persistence all in one continuous flow, often spanning hundreds of lines.

Signals

  • Methods with > 200 LOC.
  • High Cyclomatic Complexity (many if/else, switch, try/catch nested).
  • Uses ExecuteSqlCommand mixed with classic Entity Framework usage.
  • Variable names like isOk, tempList, obj2.

Why it's Bad

  • Untestable: You cannot write unit units for the "Parsing" logic without setting up a full DB context.
  • Fragile: A change in the File Format requires editing the same code that handles Database Transactions.
  • Timeouts: Since it runs as a huge transaction script, it often exceeds SQL or HTTP timeout limits.

💡 The Solution

Pipeline Pattern:

  1. Reader: Reads the file -> returns raw DTOs. (Pure Logic, Testable).
  2. Validator: Checks DTOs -> returns "Clean" vs "Invalid" lists.
  3. Persister: Saves "Clean" list to DB in batches.

🔍 WEP NG Context

  • FinancialTransactionImporter.ImportPaymentToProvider is a classic example.