When to use an Abstract Class and an Interface

Abstract classes allow for default default function definition. This means that whatever class extends the abstract class will have access to this. If we have a base class where all the classes will perform the same function, then we can define that in our Abstract class. An interface is a list of functions or properties that if a class implements it, it will have to have those functions defined within it. It is a situation of “Is-A” vs “Can-Do-this”. Objects that extends an Abstract class “Is-A” base class. Objects that implement “Can-Do-This”. Now if I asked this question and got the answer, yes, that would be the correct answer. However, I want to know why one would want to use an interface over an abstract class, and vice versa.

When to prefer an interface
Back when I wrote about the importance of composition, I mentioned that it is extremely useful when you don’t want a massive hierarchical type framework. The same applies to interfaces. This isn’t my example, but its the best one Ive come across. Lets say you have an interface for a Director and another interface for a Actor.
public interface Actor{
   Performance say(Line l);
}
public interface Director{
   Movie direct(boolean goodmovie);
}
In reality, there are Actors who are also Directors. If we are using interfaces rather than abstract classes, we can implement both Actor and Director. We could even define an ActorDirector interface that extends both like this:
public interface ActorDirector extends Actor, Director{
...
}
We could achieve the same thing using abstract classes. Unfortunately the alternative would require up to 2^n (where n is the number of attributes) possible combinations in order to support all possibilities.


When to prefer an Abstract class
Abstract classes allow you to provide default functionality for the subclasses. Common knowledge at this point. Why is this extremely important though? If you plan on updating this base class throughout the life of your program, it is best to allow that base class to be an abstract class. Why? Because you can make a change to it and all of the inheriting classes will now have this new functionality. If the base class will be changing often and an interface was used instead of an abstract class, we are going to run into problems. Once an interface is changed, any class that implements that will be broken. Now if its just you working on the project, that’s no big deal. However, once your interface is published to the client, that interface needs to be locked down. At that point, you will be breaking the clients code.
Speaking from personal experiences, frameworks is a good place to show when and where to use both an abstract class and an interface. Another general rule is if you are creating something that provides common functionality to unrelated classes, use an interface. If you are creating something for objects that are closely related in a hierarchy, use an abstract class. An example of this would be something like a business rules engine. This engine would take in multiple BusinessRules as classes perhaps? Each one of these classes will have an analyze function on it.
public interface BusinessRule{
   Boolean analyze(Object o);
}
This can be used ANYWHERE. It can be used to verify the state of your application. Verify data is correct. Verify that the user is logged in. Each one of these classes just needs to implement the analyze function, which will be different for each rule.
Where as if we were creating a generic List object, the use of abstract classes would be better. Every single List object is going to display the data in a list in some form or another. The base functionality would be to have it go through its dataprovider and build that list. If we want to change that List object, we just extend it, override our build list function, change what we want and call super.buildList();
Almost everyone knows that interfaces means you are just defining a list of functions and that abstract classes has the option of providing default functionality. The snags come when you drop the ‘why would I use one over the other?’. Abstract classes and interfaces are some of the most important fundamentals of object oriented programming. Just knowing the differences between the two is not enough. When you can look at a situation and make a strong recommendation, you will known you have a much stronger knowledge of object oriented programming. Also it helps during interviews. :P .

Interfaces allow you to provide particular sections of classes within a class hierarchy to have certain abilities.

So if you had all classes in your game inheriting from an abstract class vehicle, lets say tank, plane, rocket are three that inherit from vehicle.

You might also want to enforce a fly method on plane and rocket, you shudnt include it in your base class vechicle, because then the tank could fly. So you can use interface that forces only plane and rocket to implement the method fly.


Abstract Classes Interface
Cannot be instantiated independently from their derived classes. Abstract class constructors are called only by their derived classes. Cannot be instantiated.
Define abstract member signatures that base classes must implement. Implementation of all members of the interface occurs in the base class. It is not possible to implement only some members within the implementing class.
Are more extensible than interfaces, without breaking any version compatibility. With abstract classes, it is possible to add additional nonabstract members that all derived classes can inherit. Extending interfaces with additional members breaks the version compatibility.
Can include data stored in fields. Cannot store any data. Fields can be specified only on the deriving classes. The workaround for this is to define properties, but without implementation.
Allow for (virtual) members that have implementation and, therefore, provide a default implementation of a member to the deriving class. All members are automatically virtual and cannot include any implementation.
Deriving from an abstract class uses up a subclass's one and only base class option. Although no default implementation can appear, classes implementing interfaces can continue to derive from one another.

Output from database in asp.net

<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" cellpadding="4"
width="100%" datakeynames="AutoId" allowpaging="false" enableviewstate="false">
<Columns>
<asp:BoundField HeaderText="Auto Id" DataField="AutoId" /> <asp:BoundField HeaderText="First Name" DataField="FirstName" /> <asp:BoundField HeaderText="Last Name" DataField="LastName" /> <asp:BoundField HeaderText="Age" DataField="Age" /> <asp:BoundField HeaderText="Active" DataField="Active" />
</Columns>
</asp:gridview> <hr /> <b>Navigate to: </b> <asp:literal id="litPaging" runat="server" enableviewstate="false" />
string _ConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
int _startRowIndex = 0;
int _pageSize = 2;
int _thisPage = 0;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
if (!string.IsNullOrWhiteSpace(Request.QueryString["startIndex"])) {
_startRowIndex = int.Parse(Request.QueryString["startIndex"]); _thisPage = int.Parse(Request.QueryString["page"]);
} this.BindTheGrid();
}
} private void BindTheGrid() {
var totalCount = 0; DataTable table = new DataTable(); using (SqlConnection conn = new SqlConnection()) {
conn.ConnectionString = _ConnStr; using (SqlCommand cmd = new SqlCommand("LoadPersonalDetails", conn)) {
cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@startRowIndex", _startRowIndex); cmd.Parameters.AddWithValue("@pageSize", _pageSize); SqlParameter prm = new SqlParameter("@totalCount", SqlDbType.Int); prm.Direction = ParameterDirection.Output; cmd.Parameters.Add(prm); using (SqlDataAdapter ad = new SqlDataAdapter(cmd)) {
ad.Fill(table);
}
totalCount = int.Parse(prm.Value.ToString()); }
} GridView1.DataSource = table; GridView1.DataBind(); litPaging.Text = DoPagiation(totalCount);
} private string DoPagiation(int totalCount) {
var pages = totalCount / _pageSize; int holder = 0; StringBuilder strB = new StringBuilder(); for (int i = 0; i < pages; i++)
{ if (!holder.Equals(_thisPage)) {
strB.Append("<a href=\"CustomPagination.aspx?startIndex=" + (holder * _pageSize) + "&page=" + holder + "\">Page - " + (holder + 1) + "</a> | ");
} else {
strB.Append("Page " + (holder + 1) + " | ");
} holder++;
} return strB.ToString();
} SQL SERVER STORED PROCEDURE
-- EXEC LoadPagedArticles 10, 5CREATE PROCEDURE [dbo].[LoadPersonalDetails]
-- Add the parameters for the stored procedure here@startRowIndex int,
@pageSize int,
@totalCount int out
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.SET NOCOUNT ON;
-- increase the startRowIndex by 1 to avoid returning the last record againSET @startRowIndex = @startRowIndex + 1
BEGIN
SELECT * FROM ( Select *, ROW_NUMBER() OVER (ORDER BY AutoID ASC) as RowNum FROM PersonalDetail -- put where clause here if any ) as People WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @pageSize) - 1 ORDER BY AutoID ASC SELECT @totalCount = COUNT(AutoId) FROM PersonalDetail -- put where clause here if any
END
END

Jquery for beginners

Link to jQuery’s Source Code Remotely

This is an optional technique that many developers are using today. Instead of hosting the jQuery source code on your own server, you can link to it remotely. This ensures the fastest possible download time of the source code, since many users visiting your site might have the file already cached in their browser. Here is how your <script> tag should look:
  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js?ver=1.4.0"></script>  

Running Code Unobtrusively When the DOM is Ready

The first thing you need to be up and running with jQuery is what’s called the “document ready” handler. Pretty much everything you code in jQuery will be contained inside one of these. This accomplishes two things: First, it ensures that the code does not run until the DOM is ready. This confirms that any elements being accessed are actually in existence, so the script won’t return any errors. Second, this ensures that your code is unobtrusive. That is, it’s separated from content (HTML) and presentation (CSS).
Here is what it looks like:
  1. $(document).ready(function() {  
  2.     // all jQuery code goes here  
  3. });  
Although you will normally include your jQuery code inside the above handler, for brevity the rest of the code examples in this tutorial will not include the “ready” handler.

Selecting Elements in jQuery

The jQuery library allows you to select elements in your HTML by wrapping them in $("") (you could also use single quotes), which is the jQuery wrapper. Here are some examples of “wrapped sets” in jQuery:
  1. $("div"); // selects all HTML div elements  
  2. $("#myElement"); // selects one HTML element with ID "myElement"  
  3. $(".myClass"); // selects HTML elements with class "myClass"  
  4. $("p#myElement"); // selects paragraph elements with ID "myElement"  
  5. $("ul li a.navigation"); // selects anchors with class "navigation" that are nested in list items  
jQuery supports the use of all CSS selectors, even those in CSS3. Here are some examples of alternate selectors:
  1. $("p > a"); // selects anchors that are direct children of paragraphs  
  2. $("input[type=text]"); // selects inputs that have specified type  
  3. $("a:first"); // selects the first anchor on the page  
  4. $("p:odd"); // selects all odd numbered paragraphs  
  5. $("li:first-child"); // every list item that's first child in a list  
jQuery also allows the use of its own custom selectors. Here are some examples:
  1. $(":animated"); // selects elements currently being animated  
  2. $(":button"); // selects any button elements (inputs or buttons)  
  3. $(":radio"); // selects radio buttons  
  4. $(":checkbox"); // selects checkboxes  
  5. $(":checked"); // selects selected checkboxes or radio buttons  
  6. $(":header"); // selects header elements (h1, h2, h3, etc.)  
View a list of jQuery’s selectors and custom selectors

Manipulating and Accessing CSS Class Names

jQuery allows you to easily add, remove, and toggle CSS classes, which comes in handy for a variety of practical uses. Here are the different syntaxes for accomplishing this:
  1. $("div").addClass("content"); // adds class "content" to all <div> elements  
  2. $("div").removeClass("content"); // removes class "content" from all <div> elements  
  3. $("div").toggleClass("content"); // toggles the class "content" on all <div> elements (adds it if it doesn't exist, and removes it if it does)  
You can also check to see if a selected element has a particular CSS class, and then run some code if it does. You would check this using an if statement. Here is an example:
  1. if ($("#myElement").hasClass("content")) {  
  2.     // do something here  
  3. }  
You could also check a set of elements (instead of just one), and the result would return “true” if any one of the elements contained the class.

Manipulating CSS Styles with jQuery

CSS styles can be added to elements easily using jQuery, and it’s done in a cross-browser fashion. Here are some examples to demonstrate this:
  1. $("p").css("width""400px"); // adds a width to all paragraphs  
  2. $("#myElement").css("color""blue"// makes text color blue on element #myElement  
  3. $("ul").css("border""solid 1px #ccc"// adds a border to all lists  
View more CSS-related commands for jQuery

Adding, Removing, and Appending Elements and Content

There are a number of ways to manipulate groups of elements with jQuery, including manipulating the content of those elements (whether text, inline elements, etc).
Get the HTML of any element (similar to innerHTML in JavaScript):
  1. var myElementHTML = $("#myElement").html(); // variable contains all HTML (including text) inside #myElement  
If you don’t want to access the HTML, but only want the text of an element:
  1. var myElementHTML = $("#myElement").text(); // variable contains all text (excluding HTML) inside #myElement  
Using similar syntax to the above two examples, you can change the HTML or text content of a specified element:
  1. $("#myElement").html("<p>This is the new content.</p>"); // content inside #myElement will be replaced with that specified  
  2. $("#myElement").text("This is the new content."); // text content will be replaced with that specified  
To append content to an element:
  1. $("#myElement").append("<p>This is the new content.</p>"); // keeps content intact, and adds the new content to the end  
  2. $("p").append("<p>This is the new content.</p>"); // add the same content to all paragraphs  
jQuery also offers use of the commands appendTo(), prepend(), prependTo(), before(), insertBefore(), after(), insertAfter(), which work similarly to append but with their own unique characteristics that go beyond the scope of this simple tutorial.
View more info on some of the above commands

Dealing with Events in jQuery

Specific event handlers can be established using the following code:
  1. $("a").click(function() {  
  2.     // do something here  
  3.     // when any anchor is clicked  
  4. });  
The code inside function() will only run when an anchor is clicked. Some other common events you might use in jQuery include:
blur, focus, hover, keydown, load, mousemove, resize, scroll, submit, select.
View a more comprehensive list of jQuery events

Showing and Hiding Elements with jQuery

The syntax for showing, hiding an element (or toggling show/hide) is:
  1. $("#myElement").hide("slow"function() {  
  2.     // do something once the element is hidden  
  3. }  
  4.   
  5. $("#myElement").show("fast"function() {  
  6.     // do something once the element is shown  
  7. }  
  8.   
  9. $("#myElement").toggle(1000, function() {  
  10.     // do something once the element is shown/hidden  
  11. }  
Remember that the “toggle” command will change whatever state the element currently has, and the parameters are both optional. The first parameter indicates the speed of the showing/hiding. If no speed is set, it will occur instantly, with no animation. A number for “speed” represents the speed in milliseconds. The second parameter is an optional function that will run when the command is finished executing.
You can also specifically choose to fade an element in or out, which is always done by animation:
  1. $("#myElement").fadeOut("slow"function() {  
  2.     // do something when fade out finished  
  3. }  
  4.   
  5. $("#myElement").fadeIn("fast"function() {  
  6.     // do something when fade in finished  
  7. }  
To fade an element only partially, either in or out:
  1. $("#myElement").fadeTo(2000, 0.4, function() {  
  2.     // do something when fade is finished  
  3. }  
The second parameter (0.4) represents “opacity”, and is similar to the way opacity is set in CSS. Whatever the opacity is to start with, it will animate (fadeTo) until it reaches the setting specified, at the speed set (2000 milliseconds). The optional function (called a “callback function”) will run when the opacity change is complete. This is the way virtually all callback functions in jQuery work.

jQuery Animations and Effects

You can slide elements, animate elements, and even stop animations in mid-sequence. To slide elements up or down:
  1. $("#myElement").slideDown("fast"function() {  
  2.     // do something when slide down is finished  
  3. }  
  4.   
  5. $("#myElement").slideUp("slow"function() {  
  6.     // do something when slide up is finished  
  7. }  
  8.   
  9. $("#myElement").slideToggle(1000, function() {  
  10.     // do something when slide up/down is finished  
  11. }  
To animate an element, you do so by telling jQuery the CSS styles that the item should change to. jQuery will set the new styles, but instead of setting them instantly (as CSS or raw JavaScript would do), it does so gradually, animating the effect at the chosen speed:
  1. $("#myElement").animate(  
  2.     {  
  3.         opacity: .3,  
  4.         width: "500px",  
  5.         height: "700px"  
  6.     }, 2000, function() {  
  7.         // optional callback after animation completes  
  8.     }  
  9. );  
Animation with jQuery is very powerful, and it does have its quirks (for example, to animate colors, you need a special plugin). It’s worth taking the time to learn to use the animate command in depth, but it is quite easy to use even for beginners.
More info on the animate() command
More info on other effects-related jQuery commands

Sending mail through yahoo in html href

<a target=""_blank"" href=""http://us.mc1809.mail.yahoo.com/mc/compose?to=pradeepta@TheRedVault.com"">pradeepta@TheRedVault.com</a>

Multiselect Checkboxes and Listboxes : Scripting Multiselect Elements

http://www.insidedhtml.com/tips/html/ts16/page2.asp








Whether you use a multi-select list box or multiple check boxes the server receives the same information. However, if you use JavaScript on your page, you need to manipulate the form elements slightly differently. Below are scripts from Chapter 10 of the book Inside Dynamic HTML that makes multiple checkboxes and multi-select list boxes work the same way.

Scripting Multiple-Select List Boxes

Multiple-select list boxes allow the user to select more than one item from a list. In a multiple-select list box, the value property returns only the first selected item. To determine all the selected items, the entire list of options must be enumerated using a script. The following function demonstrates how to build an array of selected items for any list box. (If you use this function with a single-select list box, the resulting array will contain only a single value.)
<SCRIPT LANGUAGE="JavaScript">
   function getSelected(opt) {
      var selected = new Array();
      var index = 0;
      for (var intLoop=0; intLoop < opt.length; intLoop++) {
         if (opt[intLoop].selected) {
            index = selected.length;
            selected[index] = new Object;
            selected[index].value = opt[intLoop].value;
            selected[index].index = intLoop;
         }
      }
      return selected;
   }
</SCRIPT>

Using Check Boxes for Small Lists

If the number of options is small, it might make more sense to use a set of check boxes instead of a multiple-select list box. By sharing the same name across each check box in the set, the check boxes will have the same submit behavior as the multiple-select list box. The preceding function can be rewritten as shown in the following code to determine which check boxes are selected. Rather than enumerating the options collection contained in the Select element, however, you must enumerate the Form elements with a given name. Instead of passing an options collection to the function, the collection of check boxes is used. Another distinction is that check boxes expose a checked property for determining whether they are selected, while the list box uses the selected property, so the conditional logic in the function tests for either selected or checked.
<HTML>
   <HEAD>
      <TITLE>Multiple-Select Check Boxes</TITLE>
      <SCRIPT LANGUAGE="JavaScript">
         function getSelected(opt) {
            var selected = new Array();
            var index = 0;
            for (var intLoop = 0; intLoop < opt.length; intLoop++) {
               if ((opt[intLoop].selected) ||
                   (opt[intLoop].checked)) {
                  index = selected.length;
                  selected[index] = new Object;
                  selected[index].value = opt[intLoop].value;
                  selected[index].index = intLoop;
               }
            }
            return selected;
         }

         function outputSelected(opt) {
            var sel = getSelected(opt);
            var strSel = "";
            for (var item in sel)       
               strSel += sel[item].value + "\n";
            alert("Selected Items:\n" + strSel);
         }
      </SCRIPT> 
   </HEAD>
   <BODY> 
      <FORM NAME="ColorSelector">
         <INPUT TYPE=CHECKBOX NAME="color" VALUE="Red">Red
         <INPUT TYPE=CHECKBOX NAME="color" VALUE="Navy" CHECKED>Navy
         <INPUT TYPE=CHECKBOX NAME="color" VALUE="Black">Black
         <INPUT TYPE=CHECKBOX NAME="color" VALUE="White" CHECKED>White
         <INPUT TYPE=BUTTON VALUE="Selected Check Box Items" 
            ONCLICK="outputSelected(this.form.color);">
         <P>
         <SELECT NAME="multistore" SIZE=3 MULTIPLE>
            <OPTION VALUE="Computer" SELECTED>Computer</OPTION>
            <OPTION VALUE="Bookstore">Book Store</OPTION>
            <OPTION VALUE="MailOrder" SELECTED>Mail Order</OPTION>
         </SELECT>
         <INPUT TYPE=BUTTON VALUE="Selected List Items" 
            ONCLICK="outputSelected(this.form.multistore.options)">
      </FORM>
   </BODY>
</HTML>

On mouseover anchor tag text color change

<a target="_blank" class="change" href="http://google.com" style="text-decoration:none;text-align:center"><font  size="+1" face="Adobe Garamond Pro Regular">http://google.com</font></a>
           
            <style type="text/css"><!--

a.change, a.change:link, a.change:visited{background:transparent;color:#0000FF;}
a.change:hover, a.change:focus, a.change:active{background:transparent;color:#FF0000;}

--></style>