---
title: No Business Logic in Constructors
impact: MEDIUM
impactDescription: keeps instantiation simple and testable
tags: quality, construction, clean-code, python
---

## No Business Logic in Constructors

Constructors should only assign dependencies and state. Complex logic, I/O, or remote calls make testing and inheritance difficult.

**Incorrect:**
```python
class SparkJob:
    def __init__(self, path):
        self.path = path
        # ❌ I/O in constructor makes it hard to unit test
        self.spark = SparkSession.builder.getOrCreate()
        self.df = self.spark.read.load(path)
```

**Correct:**
```python
class SparkJob:
    def __init__(self, spark_session):
        self.spark = spark_session

    def load_data(self, path):
        return self.spark.read.load(path)
```
