Last Revision — April 19, 2022
1 Min Read
Inconsistent Solution
Bloaters
Duplication
Between Classes
- Duplicated Code (co-exist)
- Alternative Classes with Different Interfaces (family)
- Dubious Abstraction (caused)
- Shotgun Surgery (causes)
Joshua Kerievsky in cheatsheet (2005): "Smells to Refactorings Cheatsheet"
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].
This smell often occurs when there is some recognized method of calling a set of classes whose interfaces are not uniform.
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.
class Instrument:
...
class USB2(Instrument):
def __init__(self, ip, port):
connection = socket.new_connection(f"{ip}:{port}")
...
def ask(self, command):
...
self.connection.query(command)
class USB3(Instrument):
def __init__(self, address):
connection = socket.new_connection(address)
...
def read(self, command):
...
self.connection.query(command)
class SocketAdapter:
def __init__(self, ip, port):
connection = socket.new_connection(f"{ip}:{port}")
...
def query(self, command):
...
class Instrument:
connection: SocketAdapter
...
class USB2(Instrument):
def __init__(self, ip, port):
self.connection = SocketAdapter(ip, port)
...
class USB3(Instrument):
def __init__(self, ip, port):
self.connection = SocketAdapter(ip, port)
...