Category
Other Smells
Smells that do not fit the main groups, currently the gap left when a library class you cannot edit lacks an operation you need.
What these smells share
This group holds smells that cross the boundaries of the main categories. The current member concerns code you do not own. You cannot refactor a third-party or generated class directly, so the usual moves, such as adding a method where the data lives, are not available. The smell is in how your code works around that limit.
Members
- Incomplete Library Class: a library type lacks a method you need, and workarounds for it are duplicated across your code.
How to choose within this category
- If the type you want to change is yours, this is not the right category. Look at Feature Envy or Duplicate Code instead.
- If the type is from a library and you need one or two extra operations, treat it as Incomplete Library Class with Introduce Foreign Method.
- If you need many extra operations on the same library type, use Introduce Local Extension, or an Adapter when you also want to hide the library's interface.
For agents
- Check whether an installed dependency or a newer version of the library already provides the operation before writing one.
- Use the language's extension mechanism where one exists: C# extension methods, Kotlin extension functions, Swift extensions, Rust traits.
- Never patch the library's prototype or vendored source to add the method.
In this category
See also
- CouplersSmells where classes depend too much on each other's data or structure, or where delegation is overused, so one change ripples through others.
- DispensablesSmells where code, comments or abstractions add nothing, and removing them makes the program shorter and clearer with no loss of behavior.
- Introduce Foreign MethodAdd a helper in your own code that takes an instance of a class you cannot change and provides the method it lacks.
- Introduce Local ExtensionWrap or subclass a class you cannot change in your own class that adds the methods you need.
Original writing and examples. Topic coverage follows Refactoring.Guru, which explains this topic with its own illustrations.