Let’s Start Simple

January 11, 2007

Before we talk about asp.net and all its cool features, we need to understand a little bit about the programming languages that can be used. The two languages that Microsoft provides are C# and VB.net. Either language will work just fine, but my preference is C#. So, all the sample code that I provide will be written with C#.

Ok, let’s get started. In this posting I wanted to start simple by just discussing the C# language and some of its uses. The best way to do this is with an example. The example below shows deals with creating some objects and defining them. I decided to use racecars as my example objects. Take a look at the code below for further details.

 This sample was created using VS2003, but will work in VS2005. For the purpose of creating a simple sample I choose to make it a console application, but the code will work very much the same if it were called from an asp.net page.

Listing 1

blog2a.JPG

The source code for this can be downloaded here. This sample shows a simple Class called FordRaceCar. This Class has many properties and methods that can be called and set. A FordRaceCar Object is created and set in Main( ) method of the RaceTrack Class.

This Main( ) method is the entry point for the application. Its equivlant to PageLoad( ) in asp.net

The main problem with this code is what if we wanted to create a ChevyRaceCar? We could take all the code for the FordRaceCar Class copy it, and call it ChevyRaceCar Class. The problem here is we would now have a lot of duplicated code. This would lead to poorly maintainable code.

A better solution is to use Inheritance. We would create one base class that has all the methods and properties that would apply to RaceCars in general, and then we could inherit this base class into our specific FordRaceCar and ChevyRaceCar Class. This would avoid the duplicate code. We are also going to have an interface to define our base RaceCar class. The Interface is nothing more than a contract that says what a base RaceCar must have. In this case, the only property being enforced here is “Tires”. This means that a base RaceCar must have code to define the car tires. The interface does not contain any implemented code, only the contract. All the source code below can be downloaded here.

 blog1b.JPG

 blog1c.JPG

Listing 6

 Listing 5


Where is this going?

January 4, 2007

I thought before I start blogging about what I think is great about asp.net and the Microsoft .net technologies, I should give a little background about myself so everyone can have a better understanding of where I’m coming from, but then I figured that if you really wanted to know about me, you could just visit that section of my blog. So anyway, here we go.

 

There are two concepts that make asp.net the best web platform. The first is that since it support C# and VB.net as languages for development and both of these are fully object orientated languages, this means that we can maximize all the great features that a oo language gives us, such as encapsulation, inheritance, and strong value types.

 

I know there are other web platforms that support oo languages, such as jsp. This brings us to the second concept that makes asp.net the best. That’s the .Net framework itself. The framework has a vast number of classes that we can use, inherit, or override. This is a great time saver since we don’t need to write code to perform every minor task that we need to do. Over the next few weeks I’m going to spend some time blogging in depth about concrete examples of how asp.net leverage the oo languages and the .Net framework to perform some complicated task with ease of use to the developer.

 

Stay tuned.