.Net Technologies

Learning Design Patterns – Command Pattern

This week I'll be taking charge of the Command Pattern in my series on design patterns plucked from this book and from examples on the Internet.

What is it?

A simple analogy for the Command Pattern is a remote control. When you are clicking through your 637 channels looking for something in English that isn't tying to sell you something or change your political or religious point of view, you're giving commands to your remote, which then tells the system to increment the channel by one.

And when you use a universal remote and set your TV to channel 3, your VCR to channel F1, your sound system to Video, and then turn on your DVD player to watch a movie you rented from Blockbuster because nothing is on TV; your remote is issuing commands like "On" to each device, and the device is responsible for taking care of the details of turning itself on. If your remote was hardwired to turn on each component, you would have to open it up and add more code each time you switched out one TV for another – that's tightly coupled!

The Command Pattern can include more than just the ability to encapsulate requests; it can also queue up commands and log them, and support an "Undo" operation. By extending the pattern slightly, you can also create the ability to run a macro command that executes several commands at once – imagine a universal remote that has an "all-on" button that turns all of your devices on at once.

Learning Design Patterns - Decorator Pattern

This week I'll be hanging the Decorator Pattern in my series on design patterns plucked from this book and from examples on the Internet.

What is it?
An important design rule is to design your code to be open for extension, but closed for modification, and the Decorator Pattern is one way to go about extending existing code. The decorator wraps up an existing object and then adds functionality to it; and since the decorator is of the same type as the object it wraps, the effect should be seamless for client code (unless client code is relying on the concrete type of the original object).

Learning Design Patterns - Factory Pattern

This week I'll be manufacturing the Factory Pattern in my series on design patterns plucked from this book and from examples on the Internet.

.NET: CausesValidation, Validating and the Escape Key

I had a bug report recently which said that some of my dialog windows didn't close when the Escape key was pressed. As it was for a C# Windows Forms application, I figured I must have forgotten to set the CancelButton for the form; I was surprised I'd missed it, but it seemed like the most logical explanation.

In .NET forms, the CancelButton property can be set to a control which will be activated if the user presses the Escape key.

Master Plan v0.2

CodeSnipers has been growing pleasantly over the past few months and I believe it's reaching a critical tipping point. After the holidays, there are going to be a series of announcements about new functionality, areas, and ideas that will be coming about in this little community. If all goes well, some of them may happen when they're announced.

Anyway, towards this goal, I'm looking for a few brave people to share their thoughts, bare their souls, and generally start a discussion with the community. I'm not looking for just any people, but people with particular skills:

First, I need a .htaccess/mod_rewrite wizard. I'm not looking for any work to be done, but just to get some questions answered and bounce some opinions around.

Excel Compatible HTML

For the last couple of weeks I’ve been talking about adding an Excel export feature to one of my C#-based products. If you missed the previous posts, you might want to read the introduction, and last week’s What I did; an account of the options I chose, combined with an honest assessment of the decision process.

The bulk of the export feature was eventually provided by a third party component, xPort Tools, but I also used Excel compatible HTML files for one of the exports. Today, I’m going to finish off the series by explaining how to use HTML to output formatted data to Microsoft Excel.

Excel From C#: What I did.

Picking up where last week’s introduction left off, I’m going to explain how I added Excel export support to one of my products.

As a little background, in case you missed the introduction, I had a couple of feature requests from customers which involved exporting to Excel. The most important was a simple data table export, the files were probably going to be imported into other systems, so no formatting was necessary, and compatibility was the priority. The second was less important, but it was going to be viewed rather than processed, and relied on the formatting of the output.

Why *you* need to learn Ruby on Rails

Editor's Note: For those of you who may have missed it, the Pragmatic Programmers have just launched a new series called "Pragmatic Fridays" and their first book was released last week. As an even more interesting note, the first one entitled "Rapid GUI Development with QtRuby" was written by our own Caleb Tennis.

In the movie "The Shawshank Redemption", after the character Brooks Hatlan got out of prison (after being cooped up for a very long time), he opines that: "...The world went and got itself in a big damn hurry". He wasn't able to cope in the outside world after living in prison for so long. He liked his old lifestyle better.

The same thing exists in software/tech world. In order to survive, you've got to stay afloat with knowing something about the latest and greatest happenings. No doubt you know that Microsoft is releasing a new version of Windows next year called "Vista". I'm sure you're aware of lots of the latest gadgets coming out of Steve Jobs' hands.

Well, if you're a web developer, no doubt you've heard of Ruby on Rails. But, more importantly, have you tried it?

Excel from C#: An Introduction

A slight change of direction for me this week: a summary of the options available when you need to produce Microsoft Excel compatible output from C#.

I used to write Office-based VBA systems, but it’s been a few years since I really needed to work with Excel. Even so, when a customer requested some Excel export features for one of my products, I focused on compiling the appropriate data and didn’t give the actual export process a lot of thought. Obviously, I was forgetting that built-in Office functions and macros always made moving data between applications much too easy.

I realised I had to get back up to speed, and thankfully there were still plenty of options.

Debugging JavaScript: an ASP.NET developer’s approach

As an ASP.NET developer I’ve always been averse to writing JavaScript. One of the reasons I shied away from writing JavaScript was because of my difficulty in debugging the code. Tossing in alerts to find errors in the code was always too reminiscent of the time I spent writing code before finding a decent IDE. Well for ASP.NET developers working in Visual Studio, there are great tools available to help you debug JavaScript. Microsoft details the methods here and here. The method I use is to simply pull up the running documents window and work from there. This gives you the standard Visual Studio debugging windows like Locals, Watch, and Command. You also get the added advantage of not having to jump into a different debugging environment when going from client side to server side code.

One of the problems I’ve found with this method is that it is IE centric. If I’m developing code that needs to work on Firefox in addition to IE, I need to use other debugging tools. Mozilla’s JavaScript debugger is code named Venkman. It’s fully featured and you have to love the Ghostbusters reference! Venkman has all the standard debugging features including Locals, Watch, and Command windows. One issue with this method is that you have to pull up the web page in Mozilla or Firefox and you’re debugging only the client side of the application. In order to debug the server side code at the same time you’ll need to attach the VS debugger to the server side process as detailed here.

The web applications I currently write have no requirements to support users of other browsers so I’m not sure what is available for those. What tools have you found for writing and debugging JavaScript that have made things easier?