True Object oriented approach in designing/developing applications is really important as it saves you from a hell of a maintenence nightmare if you are working on a medium to large scale project.

Classes , abstract classes and interfaces are the cornerstone of object oriented programming in .NET framework.And you must know , precisely in which situation you go for which one of the above.Now first start off with some definitions and then we’ll get our hands dirty with some nifty examples.

Abstract Class:

An abstract class may contain fields , properties , methods , events etc.But it doesn’t allow its consumers to instantiate its object.It rather provides some basic functionality that isn’t useful if you create its instance.However if some child class inherits it and extend its functionality to some meaningful extent then it becomes very helpful as it contains the basic logic already and child class only need to add its own flavour.You will notice that behaviour throughout in .NET framework. The .NET class library contains WebRequest and WebResponse abstract classes.But they are not very useful on their own.Instead HttpWebRequest and HttpWebResponse are the concrete classes that drive from WebRequest and WebResponse respecively are so much useful because they are specifically developed for some concrete protocols like Http. Similarly System.Drawing.Brush is another abstract class but LinearGradientBrush and SolidBrush are actual concrete classes.

Rule of thumb : Use abstract classes when you want to build some basic logic that cannot be used alone. Instead you want developers to extend their logic by building on top of your base class.

In the next post I will sum up interfaces and simple classes along with their appropriate scenarios in which they will be suitable.

Till then happy coding :)

One of the biggest hurdles in the path of a javascript developer is its debugging environment.Although some IDEs do provide some nice features but most of the developers use the same old ALERT style techniques for debugging.It works for some senario in which you know exactly what methods and fields are available on objects you are working with.BUt in most scenarios you will end up having case sensitivity issues and other typos.

The life would be much simpler if you have a complete list of methods and properties available on object but that is not provided by default in any IDE or framework.A friend of mine gave me some Javascript snippet that does the same thing for me and can be used on any javascript object.So its worth sharing ….Use it anywhere you need to know which properties and methods are available on object.

function debugObject(array,find) {
 var cnt = 0;  
var dump = "";
 var found = "Not Exists";
 for(var obj in array)  {
  cnt++;   dump = dump + "-" + obj;
   if (find == obj)   {
   found = "Method Exists";   }
  if ((cnt %5) === 0)   {
   dump = dump + "\n";   }
 }  
alert(dump);  if (find)  {
alert(found);  }
}

Pass the object to this method and it will alert you with all its methods and properties…

 

debugObject(document.getElementById('mainDiv'));
image showing the alert generated from debugObject method

image showing the alert generated from debugObject method

Happy coding….. :)

While you will find a lot of resources , tips/tricks , walk throughs about javascript on internet.Some articles/blogs really standout than others due to their usefulness and unique nature.
Here is my list of unique javascript resources that I maintained as my bookmark list and every now and then I revisit them to brush up my JS skills :) .The list is ever-growing , so don’t hesitate to suggest me some useful blogs/articles if you know any.I’ll include it on this post to make it as comprehensive javascript resource gateway as possible.(The list is not in  any particular order). Enjoy scripting…. :)

Long live Javascript ;)

Usefull prototype methods for JavaScript

While working on some application , I came across a situation where I need to return more than one values/types from a method.Last time when I encounter that situation , I used C#’s ‘ref’ keyword to return additional values other than return type.

Now after using TryParse method of C#(which uses ‘out’ ) , I googled a lot for the differences between ‘ref’ and ‘out’ keywords and got some interesting differences.Here are my differences.These might be not precise but atleast give you some  insight among the two.

First of all compiler doesn’t consider any differences among the two.You can check this out by creating two method overloads with only difference in parameters is ref and out keywords.Secondly , they are both used to return more than one value from a method.Here is the only difference…

Out : when you pass a parameter using out keyword , the methods expects that the variable is only declared outside method scope and not initialized.It will perform its business logic and then initializes the variable passed as out keyword with new the value which can be accessed outside method scope.

Ref: when you pass a parameter using ref keyword , the method expects that the variable is not only declared outside method scope but also initialized to some meaningful value.It will perform its business logic and updates the variable passed as ref keyword with the new value.

So , if both keywords do the same thing (returning additional values from method),then whats the point of making two different keywords ?

There is a principle known as CODE SPEAKS which says that the code should itself describe its usage.Its the most basic easily forgettable principle. Consider the following rule of thumb when you are using these keywords:

if your method simply requires to return additional values and the parameter(s) passed in as ref/out keyword doesn’t participate in business logic , then always use the out keyword cause it strongly gives the message to developer that is going to consume your method that the value you passed as out keyword is not making any any difference in calculation/logic.So you don’t need to even initialize it.

Where as when your method uses the parameter(s) passed in as ref/out keyword in some logic  and updates it if necessary , always use the ref keyword cause it conveys its intent strongly to people consuming your method that they should declare and initialize the parameter(s) to some meaningful default and then call the method because these initialization values may change the methods output.

You can find this principle all over the .Net framework for example in TryParse and TryParseExact methods to name a few.It makes life easier for people consuming other people’s classes.

 

Happy coding :)

N2cms is one of the lightest yet smartest open source asp.net based cms out there.But it has a big disadvantage i.e lack of documentation.So here is my try to solve the most basic problem that almost every new user of n2cms fac es in his/her pathetic life : ) i.e how to use default page templates/parts of n2?

In order to use existing Templates and Themes from Templates project , you need to first download N2 Templates project(WebForm) from here.Then include following dlls into your project .

  • N2.management.dll
  • N2
  • N2.Templates

Then copy ‘Templates’ folder from Templates Project into your project root.Remove all .cs/.vb files from your templates folder – (you need to remove them else it’ll give error). Now you re up and running….just add a new start page and right click on it to add new pages.You will get all the default templates from N2.

Happy coding.. :)

If you are looking for some clientside library for your web application , then you have plenty of choices around the net.Just type your query on google and hundreds or even thousands of frameworks appear in front of you. But believe me, Extjs is not just another javascript framework.

It offers more than you even imagine.And the best thing is its real Object oriented approach that most of other frameworks clearly lacks.It has very comprehensive documentation, architecture , layout. Even a dump javascript programmer like me can enjoy writing real OO code in it.

Refer to these links for further help.I will write a definite tutorial regarding this in near future.

- www.extjs.com/

- examples.extjs.eu/

My very First Blog

Posted: February 5, 2009 in Uncategorized
Tags:

Hi all, This is my very first blog.I created this blog to share with you people some rough thoughts here and there.I hope that you will enjoy this blog as I’ll try to update this blog as frequently as possible

Regards

Imran Zahid