Structs: what are they and what are they good for?

If you extracted that struct to a proper class, it’d serve the very same purpose and leave your code simpler to read. It could handle the decision to return either the actual balance response or your struct (which sounds like a null object). Then get_balanced_card_details is a one-liner, with the switching logical all contained in a separately testable class.

1 Like