Using object state to control flow in procedures (antipattern)

class AntimatterCondenser(object):
def __init__(self):
self.__needs_to_send_report = False
def condense(self, container):
self.__purify(container)
self.__heat(container)
# ... some other actions
if self.__needs_to_send_report:
self.__send_report()
def __purify(self, container):
# ... do stuff
if contamination_found:
self.__needs_to_send_report = True
def __heat(self, container):
# ... do stuff
if too_much_heat_reached:
self.__needs_to_send_report = True
def __send_report(self):
# ...
def condense(self, container):
self.__needs_to_send_report = False
self.__purify(container)
self.__heat(container)
# ... some other actions
if self.__needs_to_send_report:
self.__send_report()
def condense(self, container):
contamination_detected = self.__purify(container)
temperature_reached = self.__heat(container)
# ... some other actions
if (contamination_detected > SAFE_CONTAMINATION_LIMIT or
temperature_reached > SAFE_TEMPERATURE_LIMIT):
self.__send_report()

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Carles Climent

Carles Climent

More from Medium

Scalable, Shard-able, Containerized & Distributed Computing

Synchronization in Multithreading

Is The Thread-per-Request Model a Good Thing After Project Loom?

What is reference?