Classes and instances
Each object is different from other objects, but there may be similarities between some objects.
A class is an abstraction of an object that is an instance of a class.
Class
function StringBuffer () {
this.__strings__ = new Array ();
}
Stringbuffer.prototype.append = function (str) {
This.__strings__.push (str);
};
stringbuffer.prototype.tostring = function () {
Return This.__strings__.join ("");
};
Objects that share the same behavior can be considered to belong to the same class, and a "class" is a general classification of all similar objects.
A class is actually a prototype of a type of object that defines state and behavior, and it represents an abstraction of something common in real life.
Class with the attribute, it is the abstract of the state of the object, using data structure to describe the properties of the class
Class has operations, it is an abstraction of an object's behavior, an operation name, and an implementation-action-folding method to describe
Class allows me to describe the general behavior of a set of objects in one area, and then create objects that behave that way when we need them.
Instance
The object that a class behaves in a prescribed manner is called an "instance" of this class. All objects are instances of certain classes, and once an instance is created, it behaves as if it were another instance of the class. The ability to receive messages to complete any operation specified by the method. In order to perform other operations in its name, this instance can also invoke other instances, or it can be instances of other classes.
Inherited
Inheritance is an effective way to extend an existing type in an object-oriented language
A class is an extension to an inherited class.
Inheritance is the mechanism by which subclasses automatically share data structures and methods of the parent class, this is a relationship between classes that, when defining and implementing a class, can be done on the basis of an already existing class, taking the content defined by the existing class as its own content and adding a few new things.
Inherited attributes are single inheritance:
Subclasses can have only one superclass, and superclass may have multiple subclasses
Subclass inherits all members of non-private classes in superclass
Subclasses can create their own members
Subclasses cannot inherit the constructors of superclass, but allow subclasses to access constructors of super classes
Sub-class/derived class
A subclass is a class that inherits behavior from another class, and a subclass usually increases its behavior in order to define its own unique kind of object.
Super class/Parent class/base class
A superclass is a class that inherits special behavior. A class can have a superclass, and can have multiple superclass types.
Abstract class
Classes that do not need to produce an instance and declare the existence of a method without implementing it are called "abstract classes." An abstract class cannot be instantiated, it can only be used as a superclass of other classes. They are just a kind of existence that can extract common factors into a common place, make a definition there (if necessary, modify it once later) and use it again and again. Abstract classes fully define their behavior, but they do not need to be fully implemented, and they can also define methods that are redefined by all subclasses. There may be a default implementation of a behavior to prevent system errors by improving or increasing the methods implemented in subclasses
See a common ASP tutorial. NET Access Data Access class
using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.web.ui.webcontrols.webparts;
Using System.Web.UI.HtmlControls;
Using System.Data.OleDb;
My using.
Using System.IO;
<summary>
Security--manage User--role--power--resource
</summary>
<summary>
Dbutil
</summary>
Public abstract class Dbutil
{
public static string connectionstring = Configurationmanager.apps Tutorial ettings["ConnectionString"].tostring () + System.web.httpcontext.current.server.mappath (configurationmanager.appsettings["DBPath"]);
<summary>
Internal function to prepare a command for execution by the database
</summary>se
<param name= "cmd" >existing command object</param>
<param name= "conn" >database connection object</param>
<param name= "Cmdtype" >command type, e.g. stored Procedure</param
<param name= "Cmdtext" >command text</param>
private static void PrepareCommand (OleDbCommand cmd, OleDbConnection conn, CommandType Cmdtype, string cmdtext)
{
Open the connection if required
if (conn.state!= ConnectionState.Open)
Conn.Open ();
Set up the command
Cmd.connection = conn;
Cmd.commandtext = Cmdtext;
Cmd.commandtype = Cmdtype;
}
<summary>
Execute an OracleCommand (this returns no ResultSet) against an existing database transaction
Using the provided parameters.
</summary>
<remarks>
e.g.:
int result = ExecuteNonQuery (trans, CommandType.StoredProcedure, "Publishorders", New OracleParameter (":p rodid", 24 ));
</remarks>
<param name= "CommandText" >the stored procedure name or Pl/sql command</param>
<returns>an int representing the number of rows affected by the command</returns>
public static int ExecuteNonQuery (string cmdtext)
{
Create a new Oracle command
OleDbCommand cmd = new OleDbCommand ();
Create a connection
using (OleDbConnection connection = new OleDbConnection (configurationmanager.appsettings["ConnectionString"). ToString () + System.web.httpcontext.current.server.mappath (configurationmanager.appsettings["DBPath")))
{
Prepare the command
PrepareCommand (cmd, connection, CommandType.Text, Cmdtext);
Execute the command
int rowsaffected = Cmd.executenonquery ();
return rowsaffected;
}
}
///<summary>
///Execute a SELECT query that'll return a result Set
///</summary>
///<param name= "commandtext" >the stored Procedure name or Pl/sql command</param>
///<returns></returns>
& nbsp; public static OleDbDataReader ExecuteReader (string cmdtext)
{
//create the command and connection
OleDbCommand cmd = new OleDbCommand ();
OleDbConnection conn = new OleDbConnection ( configurationmanager.appsettings["ConnectionString"].tostring () + System.web.httpcontext.current.server.mappath ( configurationmanager.appsettings["DBPath"]);
Try
{
Prepare the command to execute
PrepareCommand (CMD, conn, CommandType.Text, Cmdtext);
Execute the query, stating that's the connection should close-when the resulting DataReader has-been read
OleDbDataReader rdr = Cmd.executereader (commandbehavior.closeconnection);
return RDR;
}
Catch
{
If a error occurs close the connection as the reader won't be used and we expect it to close the connection
Conn.close ();
Throw
}
}
<summary>
Execute a OracleCommand that returns the ' the ' of the ' the ' the ' the ' the ' the ' the ' the database specified in the Conne Ction string
</summary>
<param name= "CommandText" >the stored procedure name or Pl/sql command</param>
<returns>an object that should is converted to the expected type using convert.to{type}</returns>
public static Object ExecuteScalar (String cmdtext)
{
OleDbCommand cmd = new OleDbCommand ();
using (OleDbConnection conn = new OleDbConnection (configurationmanager.appsettings["ConnectionString"].tostring () + System.web.httpcontext.current.server.mappath (configurationmanager.appsettings["DBPath"]))
{
PrepareCommand (CMD, conn, CommandType.Text, Cmdtext);
Object val = Cmd.executescalar ();
return Val;
}
}
///<summary>
///Execute BLOB format file upload SQL
///</ Summary>
///<param name= "cmdtext" >sql command, using the ": Files" flag file field value </param>
///<param name= "Filefullname" > File full path </param>
///<returns ></RETURNS>
public static int UploadFile (string cmdtext, string filefullname)
{
//Create a new Oracle command
OleDbCommand cmd = new OleDbCommand ();
Create a connection
using (OleDbConnection conn = new OleDbConnection (configurationmanager.appsettings["ConnectionString"].tostring () + System.web.httpcontext.current.server.mappath (configurationmanager.appsettings["DBPath"]))
{
Prepare the command
PrepareCommand (CMD, conn, CommandType.Text, Cmdtext);
Upload file
FileStream fs = File.openread (Filefullname);
byte[] content = new Byte[fs.length];
Fs.read (content, 0, content.length);
Fs.close ();
Cmd.parameters.add ("@files", system.data.oledb.oledbtype.binary). value = content;
Execute the command
int rowsaffected = Cmd.executenonquery ();
return rowsaffected;
}
}
public static DataSet GetDataSet (String cmdtext)
{
OleDbCommand cmd = new OleDbCommand ();
using (OleDbConnection conn = new OleDbConnection (configurationmanager.appsettings["ConnectionString"].tostring () + System.web.httpcontext.current.server.mappath (configurationmanager.appsettings["DBPath"]))
{
PrepareCommand (CMD, conn, CommandType.Text, Cmdtext);
OleDbDataAdapter apr = new OleDbDataAdapter (cmd);
DataSet ds = new DataSet ();
Apr.fill (DS);
return DS;
}
}
}