Search This Blog

24 June 2012

Proprties of OOPs

What is Encapsulation (or information hiding)?

Encapsulation is wrapping of data into a single unit. It is the process of keeping state and behavior of the object in a single unit and exposing public methods to act upon the state means hiding internal data of the object from the outside world.
In OOP the encapsulation is mainly achieved by creating classes, the classes expose public methods and properties. The class is kind of a container or capsule or a cell, which encapsulate the set of methods, attribute and properties to provide its indented functionalities to other classes. In that sense, encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system. That idea of encapsulation is to hide how a class does it but to allow requesting what to do.

There are several other ways that an encapsulation can be used, as an example we can take the usage of an interface. The interface can be used to hide the information of an implemented class.

IStudent myStudent = new LocalStudent();
IStudent myStudent = new ForeignStudent();

According to the sample above (let’s assume that LocalStudent and ForeignStudent are implemented by the IStudent interface) we can see how LocalStudent and ForeignStudent are hiding their, localize implementing information through the IStudent interface.

What is Abstraction ?

Abstraction is the act of identifying the relevant qualities and behaviors an object should possess without representing background details.
The importance of abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects. Abstraction is essential in the construction of programs. It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.

22 February 2012

What is OOP

understand the object orientation, let’s take your “hand” as an example. The “hand” is a class. Your body has two objects of type hand, named left hand and right hand. Their main functions are controlled/ managed by a set of electrical signals sent through your shoulders (through an interface). So the shoulder is an interface which your body uses to interact with your hands. The hand is a well architected class. The hand is being re-used to create the left hand and the right hand by slightly changing the properties of it.

What is an Object
An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behavior. For example, the hand can grip something or a Student (object) can give the name or address.
In pure OOP terms an object is an instance of a class.

What is Class
A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.
SYNTAX:

public class Student{
}
According to the sample given below we can say that the student object, named objectStudent, has created out of the Student class.

Student objectStudent = new Student();

In real world, you'll often find many individual objects all of the same kind. As an example, there may be thousands of other bicycles in existence, all of the same make and model. Each bicycle has built from the same blueprint. In object-oriented terms, we say that the bicycle is an instance of the class of objects known as bicycles.
In the software world, though you may not have realized it, you have already used classes. For example, the TextBox control, you always used, is made out of the TextBox class, which defines its appearance and capabilities. Each time you drag a TextBox control, you are actually creating a new instance of the TextBox class.

22 June 2011

Session State

what is session:

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session.
Session state information is available to all pages opened by a user during single visit. Therefore, you can use session state to store user specific information. If different user are using your application,each user session has a different session state.


how to create session:


Session["name"]=txtname.Text;
//storing the value of textbox in session
Session["name"]="David";
//storing static value in session
or
Session.Add("name",txtname.Text)
Session.Add("name","David")

how to retrieve session value:

string str=Session["name"].ToString();
lbname.Text=Session["name"].ToString();


how
to destroy session's value :

An important consideration for using Session state is that the Session does expire. By default, if a user does not access their Session data within 20 minutes (by default), the Session will expire and all items that had been stored in the Session will be discarded. Because of this, it is important to check the object that is returned from the Session to see if it exists or if it is null before you try to work with it.

if(Session["name"]!=null)
{
lbname.Text=Session["name"].ToString();
}


The Session Timeout is adjustable through a web.config setting but increasing the timeout value can put memory pressure on your server that may be undesirable.



forcefully destroy the session value, other session methods are:
  • Session.Abandon() - removes the Session and all items that it contains
  • Session.Clear() - removes all items from the Session
  • Session.RemoveAll() - removes all items from the Session
  • Session.Remove("itemName") - removes the item that was stored under the name "itemName"



17 June 2011

AutoPostBack Property


Autopostback is the mechanism, by which the page w
ill be posted ,back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back, which if set to true, will send the request to the server when an event happens in the control. If this property is set to TRUE the automatic post back is enabled, otherwise FALSE. Default value of AutoPostBack property is FALSE.

For Example



Why we need to set autopostback=true of controls

Consider a scenario where the web page is used for entering the user information. The page contains two dropdownlist controls ddlcountry and ddlstate. When user selects the country, the appropriate states be filled in the ddlstate which is loaded from the database. For achieving this requirement, we can set the autopostback property of ddlcountry to true. If we do that we can handle the event in the server side and write code to populate the ddlstate with the values from the database.
This is how we use the autopostback property.


By default the button,linkbutton and imagebutton has an autopostback as an event. The code behind that you write is to handle this postback. A button cannot have an explicit button postback but is in-built.

How to print the values of Asp controls

lbname.Text= txtname.Text

lbhobby.Text=ddlhobby.SelectedItem.Text //printing text field data

lbhobby.Text=ddlhobby.SelectedItem.Value //printing value field data

lbgender.Text=rdbmale.Text

lbcolor.Text=chkcolor.Text

lbphoto.Text=FileUpload1.Filename

lbid.Text=HiddenField1.Value

31 May 2011

Marquee Property

How to move images in up direction and to start/stop movement whenever cursor on image
<marquee onmouseover="stop()" onmouseout="start()" direction="up">

for speed and behaviour
<marquee scrollamount="4" behavior="alternate">

Width : How wide the marquee is . eg:
<marquee width="200">
hello

Height : How tall the marquee is. eg:
<marquee height="200">
hello
Direction : which direction marquee should scroll. eg: left,right,up,down.
<marquee direction="right">
hello

Behavior : what type of scrolling you want. eg:scroll,slide,alternate
<marquee behavior="scroll">
hello

Scrolldelay : How long to delay between each jump. eg:
<marquee scrolldelay="20">
hello

Scrollamount : How for to jump. eg:
<marquee scrollamount="2">
hello

Loop : How many times to loop.
<marquee loop="2">
hello

BGColor : Background Colour. eg:
<marquee BGColor="yellow">
hello

HSpace : Horizontal space around the marquee. eg:
<marquee HSpace="10">Hello
VSpace : Vertical around the marquee. eg:
<marquee VSpace="10">
hello






HTTP

what is HTTP ?

Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems.Its use for retrieving inter-linked resources led to the establishment of the World Wide Web.