There's no shortcut to experience. Writing good object oriented code takes experience, but here are three practices to help you get off on the right foot day one with even the grumpiest of gray beards:
Blindly following the "ask don't tell" axiom leads to lack of coherence in your example mobile class. Now your mobile class needs to know how to send a text message, alert (whatever that means), notify it's location, etc. This is as bad or worse than the "If" statements you describe. In fact, in EITHER case, I'd say that your design is flawed. Neither solution solves the design problem.
Comments
Motion Control replied ago:
"Write All Your Code Using TDD"
FAIL!
chudak replied ago:
Blindly following the "ask don't tell" axiom leads to lack of coherence in your example mobile class. Now your mobile class needs to know how to send a text message, alert (whatever that means), notify it's location, etc. This is as bad or worse than the "If" statements you describe. In fact, in EITHER case, I'd say that your design is flawed. Neither solution solves the design problem.
Voters For This Link (8)
Voters Against This Link (2)