---
title: "Refactoring String Calculator with SOLID Principles in Mind - Examples Needed"
url: "https://osherove.com/blog/2013/3/6/refactoring-string-calculator-with-solid-principles-in-mind.md"
canonical: "https://osherove.com/blog/2013/3/6/refactoring-string-calculator-with-solid-principles-in-mind.html"
published: "2013-03-06T10:30:30"
updated: "2013-03-06T10:30:30"
tags: []
author: "Roy Osherove"
description: "Given this simple implementation of string calculator , mid way, how would you refactor this, based on SOLID principles ? and how far would you go? Please note what principles you think this code breaks, and why it is…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Refactoring String Calculator with SOLID Principles in Mind - Examples Needed

By Roy Osherove March 6, 2013

**Historical article** · Originally published March 6, 2013; technical details may be outdated.

Given this simple implementation of [string calculator](https://osherove.com/kata), mid way, how would you refactor this, based on [SOLID principles](http://en.wikipedia.org/wiki/SOLID_\(object-oriented_design\))? and how far would you go?

Please note what principles you think this code breaks, and why it is important that it implement them, if at all. show how you refactored it in a gist.

> Post your own gists and tweet them [under hashtag #solidkata](https://twitter.com/search?q=%23solidkata&src=typd) and we can start a discussion on this. later I might use them in my videos, courses and presentations.

## Lessons on this topic

- [The Big Refactor](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/the-big-refactor/) · TDD Pairing Sessions - Building a Go Game
- [Refactoring Hardcore Skills](https://courses.osherove.com/courses/legacy-code-hero/refactoring-hardcore-skills/) · Legacy Code Hero
- [Where Do You Start with Legacy Code?](https://courses.osherove.com/courses/legacy-code-hero/where-do-you-start-with-legacy-code/) · Legacy Code Hero
- [A Refactoring Dillemma](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/a-refactoring-dillemma/) · TDD Pairing Sessions - Building a Go Game
- [Colors and Winners](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/colors-and-winners/) · TDD Pairing Sessions - Building a Go Game


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
