Wednesday, July 23, 2008

Design Pattern Riddle #8

If you need one or more actions,
I can be your design of choice.
I can organize your requests
or back them out, it's your choice.

Each object has it's parameters
That tells them how to act.
I am made of generic components;
Each one defines their internal pact.

a. Command

~/riddle by me

Tuesday, July 22, 2008

Design Pattern Riddle #7

q. I'm in some ways like a elaborate disguise;
a window dressing concealing something immense.
I offer an unified perspective to numerous systems;
I excel at making complex things make sense.

a. Façade

~/riddle by me

Monday, July 21, 2008

jQuery

I have recently started using jQuery and I’ve been quite impressed. I found integrating jQuery most useful while I developed my first ASP.NET MVC Preview 3 application.

jQuery was able to simplify some of the things I would have had to write nasty looking View code otherwise.

For example, I wanted to alternate every other row in a table with a different color. To do this in the View I initially created a counter variable and did a mod 2 to apply the CSS class. Once I integrated jQuery I was able to remove that messy code throughout my entire View and just replace it with…

   1: <script type="text/javascript">
   2:     $(document).ready(function(){
   3:         $("#tblList tr:odd").addClass("alternatingRow");
   4:         $("#tblList tr:even").addClass("row");
   5:     });
   6: </script>    

After I got a little familiar with jQuery I branched out and used it to create an accordion navigation menu with little effort.

   1: $("#menu li div.subMenuItems").hide();            
   2: $("#menu li div.parentMenuItem").click(function()
   3: {            
   4:     $("#menu li div.subMenuItems:visible").slideUp("slow");                
   5:     $(this).next().slideDown("slow");
   6:     return false;
   7: });

There are several other helpful areas in my ASP.NET MVC application that I found jQuery to be very convenient, efficient, and resulted in a cleaner code base.

If you haven’t used jQuery before I highly recommend you check it out.