C # Object-oriented grooming

Source: Internet
Author: User

First, the Richter conversion

(1) Subclasses can be assigned to a parent class: if there is a place where a parent class is required as an argument, we can replace it with a subclass.

(2) If the parent class is a child class object, the parent class can be strongly converted to a subclass object.

Two, the value type differs from the reference type

1, in the memory of the place is not the same.

The value of a value type is stored in the stack of memory.
The value of a reference type is stored in the heap of memory.
2, the way of transmission is different.
Value types We call value passing,

Reference types we call reference passing.
3. We learn the value types and reference types:
Value types: int, double, bool, char, decimal, struct, enum
Reference types: String, custom class, array

Iii. relationship between the Commission and the event

A delegate can substitute a method as a parameter into another method. A delegate can be understood as a pointer to a function.

Delegates and events are not comparable because the delegate is a type, the event is an object, and the following is the difference between the delegate's object (the event implemented by the Delegate) and (the standard event mode implementation) event.

The internal of the event is implemented with a delegate. Because for the event, external can only "register themselves + =, write off themselves --", the outside world can not write off other registrants, the outside world can not actively trigger events, so if using Delegate It is impossible to control the above, so the event is born with this syntax. An event is used to castrate a delegate instance, and an analogy is to castrate a List with a custom class . Events can only add,remove themselves, and cannot be assigned a value. Events can only be +=, =, not = .

Four Five main objects in ADO

Connection: The main is to open the connection between the program and the database. It is not possible to get data from the database without using the Connection object to open the database. The difference between close and Dispose ,close can also Open, Dispose is no longer available.

Command: The main can be used to send some instructions to the database, such as the database can be placed query, add, modify, delete data and other directives, and call the existence of the database stored procedures. This object is schema on the Connection object, that is, the Command object is connected to the data source.

DataAdapter: The main task is to perform data transfer between the source and the dataset , which can be placed through the command object and put the obtained data into the DataSet object. This object is schema on the Command object and provides many features that work with the DataSet.

DataSet: This object can be treated as a staging area (Cache), you can keep the data queried from the database and even display the entire database .DataSetis placed in memory.。DataSetability to store more than just a fewTable, you can alsoDataAdapterThe object obtains some data table structure such as the primary key, and can record the association between the data tables. DataSetobjects can be said to beADOmedium-weight object, the object schema in theDataAdapterobject, it does not have the ability to communicate with the data source;DataAdapterobject is treated asDataSetobjects and bridges that transfer data between data sources. DataSetcontains severalDataTable,datatabletablecontains severalDataRow.

DataReader: You can use the DataReader object when we only need to read the data sequentially and no other action is required . the DataReader Object simply reads the data from the data source one at a time , which exists in the database server instead of being loaded into the program's memory at once, and only (through the cursor) reads the current row's data. And the data is read-only and does not allow other operations. Because the DataReader restricts reading only one stroke at a time while reading the data, it can be used to save resources and be very efficient. The use of DataReader objects In addition to good efficiency, because not all the data back, it can reduce the load of the network.

ADO connection object to connect to the database, using command or dataadapter Span style= "font-family: the song Body;" > object to execute sql statement, and returns the result of the execution to datareader or dataadapter, and then use the obtained or Span style= "Font-family:times New Roman;" >dataadapter object manipulating data results.

v. enumerate Several ways to pass values between ASP.

1. using QueryString, such as ...? id=1; Response. Redirect () ....

2. use the Session variable

3. using server.transfer

4.Cookie Transmit Value

Six, three-tier architecture

The usual three-tier architecture is to divide the entire business application into the presentation layer (UI), the Business Logic layer (BLL), the data Access layer (DAL).

The purpose of distinguishing hierarchy is to "high cohesion, low coupling" thought.

Presentation layer (UI): Popular speaking is the interface that is presented to the user, which is what the user sees when they use a system.

Business Logic Layer (BLL): For the operation of the specific problem, it can also be said that the operation of the data layer, the data business logic processing.

Data Access Layer (DAL): This layer of transactions directly manipulate the database, for the addition of data, delete, modify, update, find and so on each layer is a vertical relationship.

The three-layer structure is a kind of N - layer structure, in general, the hierarchy is down-dependent, the lower layer of code does not determine its interface (contract), the upper code is not developed, the lower layer Code interface (contract) changes will make the upper layer of code changes together.

Advantages: Clear division of labor, clear, easy to debug, but also scalable.

Cons: Increased costs.

Seven, packing and unpacking

1) Object is a reference type, but its subclass Int32 cannot go to the place where Object can go (requires a reference type) , violates the principle of inheritance, So you need to put Int32 in Object to pass.

Boxing: Converting from a value type interface to a reference type.

Unboxing: Converting from a reference type to a value type.

Object null; // Reference type          1; // Boxing, boxing. Wraps a value type as a reference type.         int i1 = (int) obj;  //

2) The following three lines of code is not wrong, take inboxing or unboxing For example, explain how the memory changes

int i=ten; object obj = i; int

Analysis: There is no need for explicit type conversions when inboxing (boxing), but unboxing(unboxing) requires explicit type conversions, so the third line of code should read:

3 Int j = (int) obj;

To master boxing and unpacking, it is necessary to understand the CTS and its characteristics:

    net cts (Common Type System) is a common type system that exists to implement the rules that must be followed when the application declares and uses these types. .net Divide the type of system into two major categories : Value types and reference types.

Everything in the CTS is an object; All objects originate from a base class-theSystem.Object type. One of the biggest features of value types is that they cannot be null, and variables of value types always have a value. In order to resolve a problem where the value type is not nullableand the reference type can be null , Microsoft introduces boxing and unboxing in . Net : Boxing is simply wrapping a value type into a reference type with a reference type, and unpacking the wrapped value type data from the reference type.

Object. ReferenceEquals ();// used to determine whether two objects are the same object

Console.WriteLine (object. ReferenceEquals (3,3));// because two 3 is loaded into two boxes, it is false.

Eight the difference between heap and stack?

Stacks are allocated memory space during compilation, so your code must have a clear definition of the stack size, local value type variables, value type parameters, and so on in stack memory.

A heap is a dynamically allocated memory space during a program's run, and you can determine the size of the heap memory to allocate depending on how the program is running.

Nine what are the similarities and differences between interfaces and classes

Different points:

Interfaces cannot be instantiated directly.

An interface does not contain an implementation of a method.

Interfaces can inherit multiple, and classes can only be single-inherited.

A class definition can be split between different source files.

Same point:

interfaces, classes, and structs can inherit from multiple interfaces.

An interface is similar to an abstract base class: Any non-abstract type that inherits an interface must implement all members of the interface.

Both interfaces and classes can contain events, indexers, methods, and properties.

C # Object-oriented grooming

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.