My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
Someone rip this idea apart:

When you write an if statement in one class that's using data from an object of a different class to make a decision, ask yourself:
  1. Would this code be more appropriate in the other object?
  2. Would it be better to introduce a new object, whose purpose it is to do this?
Thoughts appreciated.

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!


Comments
Leave a comment

If OO design was so simple, languages would just remove the "if statement" e.g.

if (salary < 50000)
taxRate= 0;
else
taxRate = 20;

I can complicate the above "if" statement by adding different tax rates and tax percentages. I don't think OO design is just about removing if statements.

Posted by Vijay Nathani on Feb 22, 2012 at 08:48 AM UTC - 5 hrs

No, of course there is more to it than if statements.

But would these two questions help lead to a better (as opposed to perfect) design?

Posted by Sammy Larbi on Feb 22, 2012 at 09:03 AM UTC - 5 hrs

I think the questions are good. I also use them:-)
Other questions or thoughts: SOLID principles and so on, all the nice ideas about software development...

Posted by Thomas Eichberger on Feb 22, 2012 at 10:37 AM UTC - 5 hrs

I think its a good start of questions to get ideas flowing to the next logical steps...whatever that may be depending on the usage of the class. It could be trying to decide how the new object is introduced. For example, should I use inheritance or composition. OOP design seems confusing from overall perspective but asking simple questions help give a starting point.

Posted by Keith H on Feb 22, 2012 at 12:49 PM UTC - 5 hrs

The reek gem for ruby holds to this, as does The Anti If Campaign www.antiifcampaign.com, and it agrees with "tell, don't ask" (search for the article by the Pragmatic Programmers). People can't cope with too many nested if statements. All that is clear. So why is it so basic to human languages? I suppose the functional programming approach of template matching is pretty much all ifs, a collection of implicit case statements. So you do have to ask. The answer won't always yes to one or both. I suppose at some point browsing the class tree gets more difficult than browsing the code.

Posted by hgs on Feb 22, 2012 at 12:57 PM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)
Website

Comment:

Subcribe to this comment thread
Remember my details
Google
Web CodeOdor.com

Me
Picture of me

Topics
.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Resources
Agile Manifesto & Principles
Principles Of OOD
ColdFusion
CFUnit
Ruby
Ruby on Rails
JUnit



RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner