Suggest an editImprove this articleRefine the answer for “Give an example of an SRP violation”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**An SRP violation** occurs when a single class takes on different responsibilities that belong to different layers or aspects of the system. **Key point:** as a result, the class ends up with three reasons to change - a change in the order-creation process, a change in the email-notification format, and a change in logging requirements.Shown above the full answer for quick recall.Answer (EN)ImageAn SRP violation occurs when a single class takes on different responsibilities that belong to different layers or aspects of the system. Example: ## Example of a class that violates SRP ```python class OrderService: def create_order(self, order_data): # business logic for creating an order self._validate(order_data) self._save_to_db(order_data) # send a notification to the customer self._send_email(order_data["email"]) # write to the log file with open("orders.log", "a") as f: f.write(f"Order created: {order_data}\n") def _validate(self, data): ... def _save_to_db(self, data): ... def _send_email(self, email): ... ``` ## Breaking down the violation 1. **Business logic** The methods `create_order`, `_validate`, `_save_to_db` belong to the "orders" domain. 2. **Notifications** The `_send_email` method belongs to communications - a different responsibility. 3. **Logging** Writing to `orders.log` belongs to infrastructure - a third responsibility. As a result, the class has **three reasons to change**: - the order-creation process changes → the class must be changed; - the email-notification format changes → the same class must be changed; - logging requirements change → the same class must be changed again. This is a direct SRP violation.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.