Research Log of Web Science Students

Computer Science is not simply programming

Killing code duplication with factories

leave a comment »

I got tired of having to write the same code all over again to populate my daos just so I could unit test so I refactored my code.

Goodbye duplicate code!

BEFORE:

course1 = new Course();
course1.setOwner("Jose");
course1.setLearningObjective("to learn football");
course1.setTitle("Football");
course1.setTags("Football Soccer");

dao.insert(course1);

course2=new Course()
...
dao.insert(course2);

course3=new Course()
...
dao.insert(course3);

AFTER

Advertisements

Written by Jose Asuncion

December 4, 2009 at 9:40 am

Posted in Hardwire

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: