Overview
If a similar problem is solved differently in different parts of the project, it is an Oddball Solution. This code smell could also have been classified under Duplicated Code, although it is not exactly a one-to-one copy-paste - it is more subtle [1].
Causation
This smell often occurs when there is some recognized method of calling a set of classes whose interfaces are not uniform.
Problems
🧩
Increased Complexity
There should be one way to deal with the problem throughout the project. There is no reason to keep two ways of dealing with one problem - just use the better one.
📋
Duplication
Example
1class Instrument:
2 ...
3
4class USB2(Instrument):
5 def __init__(self, ip, port):
6 connection = socket.new_connection(f"{ip}:{port}")
7 ...
8
9 def ask(self, command):
10 ...
11 self.connection.query(command)
12
13
14class USB3(Instrument):
15 def __init__(self, address):
16 connection = socket.new_connection(address)
17 ...
18
19 def read(self, command):
20 ...
21 self.connection.query(command)Refactoring
- Unify Interfaces with Adapter
Sources
- ORIGIN