Refactor Monolithic God Classes into Clean Services
Get a step-by-step plan to break a large monolithic class into smaller, testable services while preserving the original public API behavior.
Agent prompt for ChatGPT and Claude
Prompt
mkdir -p .agents/skills/refactor-monolithic-god-classes-into-clean-services && curl -sL "https://prompts-gpt.com/prompts/refactor-monolithic-god-classes-into-clean-services/raw" -o .agents/skills/refactor-monolithic-god-classes-into-clean-services/SKILL.md---
name: refactor-monolithic-god-classes-into-clean-services
description: "Get a step-by-step plan to break a large monolithic class into smaller, testable services while preserving the original public API behavior."
---
# Refactor Monolithic God Classes into Clean Services
Get a step-by-step plan to break a large monolithic class into smaller, testable services while preserving the original public API behavior.
## Prompt
```
Act as a Senior Software Architect. Your task is to refactor a monolithic class into smaller, single-responsibility services using dependency injection. First, ask me these three questions: 1. Paste the code of the monolithic class you want to refactor. 2. List the primary responsibilities currently handled by this class. 3. Name the programming language and framework you are using. After I answer, provide a refactoring plan. Rules: 1. Identify logical groupings for new services. 2. Define an interface for each new service. 3. Update the original class to act as a facade that delegates calls to these new services to ensure no breaking changes to the existing public API. 4. Show the new dependency injection structure. Output format: # Refactoring Strategy, ## Proposed Services, ## Interface Definitions, ## Refactored Facade Implementation. This is for educational purposes and requires code review by a human lead developer before deployment.
```
## Usage Notes
Use this with GitHub Copilot or ChatGPT when your code has become too large to maintain. Paste your monolithic class when prompted. It works best for languages like Java, C#, or TypeScript where interfaces are standard.
Act as a Senior Software Architect. Your task is to refactor a monolithic class into smaller, single-responsibility services using dependency injection. First, ask me these three questions: 1. Paste the code of the monolithic class you want to refactor. 2. List the primary responsibilities currently handled by this class. 3. Name the programming language and framework you are using. After I answer, provide a refactoring plan. Rules: 1. Identify logical groupings for new services. 2. Define an interface for each new service. 3. Update the original class to act as a facade that delegates calls to these new services to ensure no breaking changes to the existing public API. 4. Show the new dependency injection structure. Output format: # Refactoring Strategy, ## Proposed Services, ## Interface Definitions, ## Refactored Facade Implementation. This is for educational purposes and requires code review by a human lead developer before deployment.Example output
Tips and common edits
Why this works
- Forces a clear separation of concerns by identifying logical groupings before writing code.
- Ensures backward compatibility by keeping the original class as a facade.
- Uses dependency injection to improve testability and modularity.
Use this with GitHub Copilot or ChatGPT when your code has become too large to maintain. Paste your monolithic class when prompted. It works best for languages like Java, C#, or TypeScript where interfaces are standard.
Common edits
- Add specific design patterns like Strategy or Factory if the logic requires complex conditional branches.
- Adjust the interface definitions to include async/await patterns if the project requires high concurrency.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Refactor Nested Procedural Code into Pure Pipelines
Transforms complex, deeply nested imperative code into clean, testable pure functions organized as a sequential data pipeline.
Plan an incremental refactor for legacy code
Break down monolith or fragile legacy modules into safe, testable milestones using branch-by-abstraction patterns.
Compare Three Feature Architectures Against Module Boundaries
Get a scored trade-off matrix comparing three feature architectures by file touchpoints, coupling risks, and rollback cost before running Cursor Composer.
Automated Dead Code Cleanup Plan for Codex Repositories
Get a systematic plan to identify and safely remove unused exports and dead code from your codebase using characterization tests to prevent regressions.
Refactor Pasted Code for Readability Without Changing Its Behavior
Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.
Refactor nested legacy loops into flat readable helper functions
Decompose deeply nested legacy loops into single-purpose functions. Use this when reviewing complex procedural code that is hard to test or debug.
- Deconstruct Monolithic Pull Requests into Atomic Commit Stacks
- Characterization Tests Before a Refactor
- Compress bloated instructions while preserving accuracy
- Split a large pull request into reviewable commits
- Decompose monolithic automation into modular subflows
- Decompose Framework Migrations into Subagent Work Batches