Some review and Summary 1

Source: Internet
Author: User
1. Polymorphism

Here we will summarize the functions of virtual override and new.
There are three classes A, B, C, B, and C inherited from a, some of which are overwritten, and some are overwritten: Public   Class A
{
Public A () {}

Public   Virtual   Void Show ()
{
Console. Write ("Show");
}

Public   Void Show2 ()
{
Console. Write ("A");
}
}

Public   Class B:
{
Public B () {}

Public   Override   Void Show ()
{
Console. Write ("Show B");
}
}

Public   Class C:
{
Public C () {}

Public   New   Void Show ()
{
Console. Write ("Show C");
}

Public   New   Void Show2 ()
{
Console. Write ("C");
}
}

Private   Void Button#click ( Object Sender, system. eventargs E)
{
A;
B =   New B ();

A = B;
A. Show ();
B. Show ();
A. show2 ();
B. show2 ();
}

Private   Void Button2_click ( Object Sender, system. eventargs E)
{< br>;
C = New C ();
A = C;
. show ();
C. show ();
. show2 ();
C. show2 ();
}

/**/ /*
Result:
Button#click:
Show B
Show B
A
A

Button2_click:
Show
Show C
A
C
*/

We can analyze the results to find out:
The Declaration class mentioned below refers to A, and the instance class refers to B or C
The call sequence of methods is as follows:
If (this method in the Declaration class is a virtual method) // For example, the show () method
{
If (the referenced instance class override this method)
Return refers to the method of this instance class // For example, a A = new B (); A. Show () returns "show B"
Else
The Return Statement class method // For example, a A = new C (); A. Show () returns "show a", regardless of whether the instance class overwrites (new) This method.
}
Else
Return Declaration class method // For example, show2 () method, a A = new C (); A. show2 () returns "".

In addition:
If the Declaration class does not declare this method, you need to call the method in its parent class, for example, a A = new B ();. show2 () returns "A" because the method show2 () is not overwritten or overwritten.

2. Strong names

Strong names have two main advantages: DifferentiationProgramSet to avoid malicious changes to the Assembly.
Strong name mechanism:
First, you get a public key and a key through sn.exe.
Then, hash the executable files (excluding dos headers and PE headers) of the Assembly using the public key.AlgorithmTo obtain the object hash value.
Finally, encrypt the hash value of the file using the key to obtain a ciphertext.
In this way, there are three things in the final strong name assembly:
L Public Key ID (the last eight bytes of the hash value of the public key)
L Public Key
L ciphertext
Use the public key and executable files of the Assembly (excluding dos headers and PE headers) for hashing to obtain a file hash value, the public key and ciphertext can also be used to obtain a file hash value. If the two hash values are exactly the same, OK, verification passed.
The role of the Public Key Identifier (the last eight bytes of the hash value of the public key:
L differentiate an Assembly. As mentioned above, an assembly is one of the four attributes that distinguish one another.
L verify the Public Key

3. Transactions

Transaction attributes

Transactions have ACID properties
That is, atomic atomicity, consistent consistency, isolated isolation, durable permanent

Atomicity

That is, the transaction should be taken as a unit of work, and the transaction is processed completely. All the work is either saved in the database or completely
Rollback, all are not retained

Consistency
After the transaction is completed or canceled, it should be in the same state.

Isolation

When multiple transactions are performed at the same time, they should not interfere with each other. When a transaction is prevented from processing data that other transactions also need to modify,
Unreasonable access and incomplete data reading

Permanent
After the transaction is committed, the work is permanently saved.

Problems arising from concurrent Transaction Processing

Update loss

When two or more transactions select the same row and update the row based on the originally selected value, the update will be lost,
Every transaction does not know the existence of other transactions. The last update will overwrite the updates made by other firms, which will lead to data loss.

Dirty read
When the second transaction selects another row being updated, unconfirmed correlation issues will occur.
The data being read by the second transaction has not been confirmed and may be changed by the transaction that updates this row.

Non-repeated read

When the second transaction accesses the same row multiple times and reads different data each time, an inconsistent analysis problem occurs.
The inconsistent analysis is similar to the unconfirmed correlation because other transactions are also changing the data being read by the second transaction.
However, in an inconsistent analysis, the data read by the second transaction is committed by a transaction that has been changed. Furthermore, the inconsistent analysis involves reading the same row multiple times (twice or more) and the information is changed by other transactions each time. Therefore, the row is read non-repeatedly.

Phantom read

A phantom reading problem occurs when a row is inserted or deleted and the row belongs to the row being read by a transaction.
The row range for the first read of the transaction shows that one row no longer exists in the second read or subsequent read because the row has been deleted by other transactions. Similarly, due to the insert operation of other transactions, the second or subsequent read of the transaction shows that a row does not exist in the original read.

Three transaction processing types

Automatic Transaction Processing

By default, each T-SQL command is a transaction that is automatically started and committed by the system.

Implicit transactions

When a large number of DDL and DML commands are executed, the system starts automatically until the user explicitly commits them. You can use set implicit_transactions to switch between implicit transactions.
Set the implicit transaction mode for the connection. When set to on, set implicit_transactions sets the connection to the implicit transaction mode. When it is set to off, the connection is returned to the automatic commit transaction mode.

User-Defined transactions

User-controlled start and end commands of transactions include: Begin Tran commit Tran rollback Tran command

Distributed transactions
Transactions that span multiple servers are called distributed transactions. SQL Server can be operated by DTC Microsoft Distributed Transaction Coordinator.
To support distributed transactions. You can use the begin Distributed Transaction command to start a distributed transaction.

 

Iv. isolation level of Transaction Processing

Use the SET transaction isolation level to control the default transaction lock behavior of all statements sent by the connection.

From low to high is

Read uncommitted

Execute dirty read or 0-level isolation lock, which means no shared lock is issued or the exclusive lock is not accepted. When this option is set, uncommitted or dirty reads can be performed on the data. Before the transaction ends, the values in the data can be changed, and the rows can also appear in the dataset or disappear from the dataset. This option is used to set nolock for all tables in all statements in the transaction. This is the minimum limit among the four isolation levels.

Reference self-http://www.study888.com/computer/data/sqlsl/200506/42604.html

4. interfaces and abstract classes

Interfaces are used for standardization, and abstract classes are used for commonality.

Creating an interface is to create one or more method definitions, which must be implemented in each class that implements this interface
Method. The system does not generate any default method.Code, You must complete the implementation process on your own. The advantage of an API is that it provides
Classes are the sub-classes of two classes: one is inheritance and the other is from the sub-interface. If the class implementing this interface misses one
The compiler will generate an error.
Create-an abstract class is to create such a base class. It may have one or more complete and workable methods,
At least one method is not implemented and declared as abstract. An abstract class cannot be instantiated, but a class must be derived from it. These class packages
Including the implementation process of abstract methods. If all methods of an abstract class are not implemented in the base class, it is essentially equivalent
Interfaces. The role of an abstract class is to provide a basic class definition for how a derived class works, allowing programmers to fill in this
Implementation process.

Abstract classes are generally used as common parent classes to provide the foundation for subclass extension. The extension here includes attributes and behavior. In general, the interface does not consider attributes, but only methods, so that the subclass can freely fill or extend the methods defined by the interface.

5. cursor
Procedure
Declare, open, read cyclically, close, and release memory
Declare cursor_name [insensitive] [scroll] cursor
For select_statement
[For {read only | update [of column_name [,... n]}]

To be continued ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.