Last Revision — April 19, 2022
1 Min Read
---
Bloaters
Responsibility
Between Classes
- Afraid To Fail (caused)
- Dubious Abstraction (caused)
- Hidden Dependencies (caused)
- Duplicated Code (causes)
Steve Smith in course (2013): "Refactoring Fundamentals"
If, after the use of a class or method, several lines of code are required to:
then there is a Required Setup or Teardown Code code smell. Furthermore, this may indicate improper abstraction level.
Some functionality was taken beyond the class during development, and the need for their use within the class itself was overlooked.
Class can't be reused by itself - it requires extra lines of code outside of its scope to use it.
class Radio:
def __init__(self, ip, port):
socket = socket.connection(f"{ip}:{port}")
...
radio: Radio = Radio(ip, port)
...
# Doing something with the object
...
# Finalizing its use
radio.socket.shutdown(socket.shut_RDWR)
radio.socket.close()
...
class Radio:
def __init__(self, ip, port):
socket = socket.connection(f"{ip}:{port}")
def __del__(self):
def graceful_shutdown():
self.socket.shutdown(socket.shut_RDWR)
self.socket.close()
graceful_shutdown()
super().__del__()
...
radio: Radio = Radio(ip, port)
...
# Doing something with the object
...
# Finalizing its use no longer requires manual socket closing
...