Tuesday, February 2, 2010

Interface


An Interface in [Computer science] refers to a set of named operations that can be invoked by clients. Interface generally refers to an abstraction that an entity provides of itself to the outside. This separates the methods of external communication from internal operation (for example two different functions written in C language have the same interface if they have the same arrangements of arguments and the same type of return value, but the function body may be implemented in different way), and allows it to be internally modified without affecting the way outside entities interact with it, as well as provide multiple abstractions of itself. It may also provide a means of translation between entities which do not speak the same language, such as between a human and a computer. Because interfaces are a form of indirection, some additional overhead is incurred versus direct communication.


The interface of a software module A is deliberately kept separate from the implementation of that module. The latter contains the actual code of the procedures and methods described in the interface, as well as other "private" variables, procedures, etc.. Any other software module B (which can be referred to as a client to A) that interacts with A is forced to do so only through the interface. One practical advantage of this arrangement is that replacing the implementation of A by another one that meets the same specifications of the interface should not cause B to fail—as long as its use of A complies with the specifications of the interface









// Assembly: Common Classes
namespace CommonClasses
{
public interface IAnimal
{
string Name { get; }
string Talk();
}
}

// Assembly: Animals
using System;
using CommonClasses;

namespace Animals
{
public abstract class AnimalBase
{
public string Name { get; private set; }

protected AnimalBase(string name) {
Name = name;
}
}

public class Cat : AnimalBase, IAnimal
{
public Cat(string name) : base(name) {
}

public string Talk() {
return "Meowww!";
}
}

public class Dog : AnimalBase, IAnimal
{
public Dog(string name) : base(name) {
}

public string Talk() {
return "Arf! Arf!";
}
}
}

// Assembly: Program
// References and Uses Assemblies: Common Classes, Animals
using System;
using System.Collections.Generic;
using Animals;
using CommonClasses;

namespace Program
{
public class TestAnimals
{
// prints the following:
// Missy: Meowww!
// Mr. Mistoffelees: Meowww!
// Lassie: Arf! Arf!
//
public static void Main(string[] args)
{
var animals = new List() {
new Cat("Missy"),
new Cat("Mr. Mistoffelees"),
new Dog("Lassie")
};

foreach (var animal in animals) {
Console.WriteLine(animal.Name + ": " + animal.Talk());
}
}
}
}

Friday, November 6, 2009

A reminder to myself and others, when you want to get access to your Session State from an ASHX or HttpHandler, you need to implement IReadOnlySessionState:

<% @ webhandler language="C#" class="DownloadHandler" %>

using System;
using System.Web;
using System.Web.SessionState;

public class DownloadHandler : IHttpHandler, IReadOnlySessionState
{
public bool IsReusable { get { return true; } }

public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write(ctx.Session["fred"]);
}
}

Sunday, March 22, 2009

History of JavaScript :

JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, which was later renamed to LiveScript, and finally to JavaScript. The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. JavaScript was first introduced and deployed in the Netscape browser version 2.0B3 in December 1995. The naming has caused confusion, giving the impression that the language is a spin-off of Java, and it has been characterized by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web-programming language.
Due to the widespread success of JavaScript as a client-side scripting language for web pages, Microsoft developed a compatible dialect of the language, naming it JScript to avoid trademark issues. JScript added new date methods to fix the non-Y2K-friendly methods in JavaScript, which were based on java.util.Date. JScript was included in Internet Explorer 3.0, released in August 1996. The dialects are perceived to be so similar that the terms "JavaScript" and "JScript" are often used interchangeably. Microsoft, however, notes dozens of ways in which JScript is not ECMA compliant.
Netscape submitted JavaScript to Ecma International for standardization resulting in the standardized version named ECMAScript.
The flexibility of JavaScript has made it one of the most popular programming languages on the web and also one of the easier languages to learn. Initially, however, many professional programmers denigrated the language because its target audience was web authors and other such "amateurs", among other reasons. The advent of AJAX returned JavaScript to the spotlight and brought more professional programming attention. The result was a proliferation of comprehensive frameworks and libraries, improved JavaScript programming practices, and increased usage of JavaScript outside of the web.

Friday, November 21, 2008

What is the DOM?

The Document Object Model is an API for HTML and XML documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation. Essentially, it connects web pages to scripts or programming languages.

All of the properties, methods, and events available to the web developer for manipulating and creating web pages are organized into objects (e.g., the document object that represents the document itself, the table object that represents a HTML table elements, and so forth). Those objects are accessible via scripting languages in most recent web browsers.

The DOM is most often used in conjunction with JavaScript. That is, the code is written in JavaScript, but it uses the DOM to access the web page and its elements. However, the DOM was designed to be independent of any particular programming language, making the structural representation of the document available from a single, consistent API. Implementations of the DOM can be built for any language.

The World Wide Web Consortium establishes a standard for the DOM, called the W3C DOM. It should, now that the most important browsers correctly implement it, enable powerful cross-browser applications. 

Wednesday, August 13, 2008

Logic puzzle: Russian Roulette:

You are tied to your chair and can't get up. Here's a gun. Here's the barrel of the gun, six chambers, all empty. Now watch me as I put two bullets in the gun. See how I put them in two adjacent chambers? I close the barrel and spin it. I put the gun to your head and pull the trigger. Click. You're still alive. Lucky you! I'm going to pull the trigger one more time. Which would you prefer, that I spin the barrel first, or that I just pull the trigger?

Database:

You can delete all rows in a table by using a Delete query.


You cannot undo the action of executing a Delete query. As a precaution, back up your data before executing a Delete query.

Wednesday, August 6, 2008

All about 'event.keyCode'

keyCode returns the "virtual-key code" from the WM_KEY* messages in the Windows API when checked in the keydown and keyup events, and the ASCII/Unicode character codes in the keypress event.

For example, the DELETE key has a hex value of 007F (127 decimal) in both Unicode and ASCII. If I inspect window.event.keyCode in the keyup event, after pressing the DELETE key, the property returns a value of 46 (decimal). The DELETE key does not generate keypress events. 46 happens to be the VKey code for a delete key on my US keyboard. (VKey codes are defined in WinUser.h.)

Likewise, the keyCode also returns 65 in the keydown and keyup events regardless of whether the character entered is an "A" or an "a". However, the keyCode actually does return a 97 for "a" and 65 for "A" in the keypress event. So beware the internal inconsistency of keyCode, depending on during which event it is inspected.

Press any key here to know Keycode:

Saturday, August 2, 2008

CSS:

Normally we assign single class to HTML element 'class' attribute. If we want to add more than one class than we could do like this..
<input class="BtnColor BtnSize" type="button" value=" Ok " >
BtnColor and BtnSize are two different class.
..
please note second one is high precedence than first..