Essential .NET reading notes

xiaoxiao2021-03-06  44

I finally read Don Box's << Essential .Net >>, feeling much, really a good book! IdiSpose interface from C #

The C # USING statement is a deterministic destructor, to implement the functionality similar to the C destructor, and clean up when the object is no longer needed. But this grammatical structure is not as clear as C destructor.

Using (t Obj1 = new t (), obj2 = new t ()) {

}

Here, the OBJ1 and OBJ2 must be the same type, and the programmer is required to express the scope of the scope of each variable. In fact, the CLR can determine the scope of the role of each object, in the garbage collection technology of C #, CLR to determine the scope of the object.

{

Object r1 = new object ();

Object r2 = new object ();

System.gc.collect ();

R2.toString ();

}

R1 will be recovered when garbage collection is carried out in the third sentence, although R1 is still in the scope of action from the perspective of semantics.

Today, read the book, see if the C # interface is realized, I feel that the grammar of the C # is more complicated. First look at the following piece

Public interface IVEHICLE

{

Void Start (); void stoc (); void Turn ();

}

Public Class Base: IVEHICLE

{

Void IVEHICLE.START ()

{

Console.writeline ("Base.Start");

}

Public void stop ()

{

Console.writeLine ("Base.Stop");

}

Public Virtual Void Turn ()

{

Console.writeline ("Base.Turn");

}

}

Public Class Derive1: Base

{

// illegally, can not cover the method of absence

// public override void start () {}

// illegal, base.stop is not a virtual function

// public override void stop () {}

// Legal, replace Base.Turn and IVEHICLE.TURN

Public Override void Turn ()

{

Console.writeline ("Derive1.Turn");

}

}

Public Class Derive2: Base, IVEHICLE

{

// Legal, re-realize IVEHICLE

Void IVEHICLE.START ()

{

Console.writeline ("Derive2.Start");

}

// Legal, re-realize IVEHICLE

Public void stop ()

{

Console.writeline ("Derive2.Stop");

}

// Legal, replace IVEHICLE.TURN (but do not replace Base.Turn)

Public void trun ()

{

Console.WriteLine ("Derive2.Turn");

}

}

Call as follows in the main function

Derive1 D1 = new derive1 ();

Console.WriteLine ("Wen Derive1 member");

// D1.Start (); // illegal call

D1.Turn (); // Call Derive1.trun

D1.Stop (); // Call Base.Stop

Console.writeline ("Derive1 converts into BASE after calling member"); base b1 = d1;

// b1.start (); // illegal call

b1.turn (); // Call Derive1.trun

B1.Stop (); // Call Base.Stop

Console.writeline ("Derive1 is converted into IVEHICLE after calling member");

Ivehicle v1 = d1;

V1.Start (); // Call Base.Start

V1.Turn (); // Call Derive1.Turn

v1.stop (); // Call Base.Stop

Derive2 d2 = new derive2 ();

Console.writeline ("Call Derive2 Member");

//d2.start();// illegal call

D2.Turn (); // Call Base.Turn

D2.Stop (); // Call Derive2.Stop

Console.Writeline ("Derive2 is converted into BASE after calling members);

Base B2 = D2;

//b2.start();// illegal call

b2.turn (); // Call Base.Turn

B2.Stop (); // Call Base.Stop

Console.writeline ("Derive2 is converted into IVEHICLE after calling member);

IVEHICLE V2 = D2;

V2.Start (); // Call Derive2.Start

v2.turn (); // Call Base.Turn

v2.stop (); // Call Derive2.Stop

operation result

Call Derive1 member

Derive1.turn

Base.stop

Derive1 is converted into base after calling members

Derive1.turn

Base.stop

Derive1 converts a member after IVEHICLE

Base.start

Derive1.turn

Base.stop

Call Derive2 member

Base.Turn

Derive2.stop

Derive2 is converted into base after calling members

Base.Turn

Base.stop

Derive2 is converted into IVEHICLE after calling a member

Derive2.start

Base.Turn

Derive2.stop

C # introduces too many complex technologies, such as implementation and inheritance of the interface. The benefits of these complexities are far less than his disadvantage. The programmer understands that these complex technologies are very difficult. Understanding will only bring errors, and smart programmers may understand and use these complex technologies to write very beautiful code, but these codes have been published. For programmers who want to use these code but not smart, it is a disaster. It has been complex technology. In addition, the intelligent programmers will be more embarrassed, and a software development team cannot be used. There is a consistent understanding with the content, and the errors of the software are of course inevitable.

More importantly, these complex technologies are not necessary, the same problem can also be solved when there is no such technology, and the method may be ugly, but as long as solving it, it can work more efficiently, it can be easier to be more It is understood that the software developed by the team can have fewer mistakes, more reliable. Java has no complex things, which is still very good for so many years. Java's mistake is too focused on platform transplantability, ignoring the most wide Windows platform, so it is not the first choice for developing desktop applications.

There is also a complicated place, the virtual function is called in the constructor, and the virtual function call is done by the non-virtual function call, but the C # is called by virtual function. To this end, the initialization step of the object is complex. More, if it assigns it when the class member is defined, the assignment will be performed before the constructor of the base class, and if it is assigned in the constructor, the assignment will be performed after the constructor of the base class. . When I arrived at the agent, it is enough to make your headaches a day.

After the C # function call is turned into a machine code, the function call rule uses __fastcall call rules

Most of the Ideas in software engineering is to control complexity

Structured Coarsely granularity is divided into complexity; OO is marked with behavior, reducing complexity with abstract methods; components approach the program into individual portions, partial connection is based on interface and protocols, thereby reducing complexity Sex. Component programming has established such a world. In this world, the components are assembled to form a complete application using advanced languages, so that there is no need to technologists can also write good applications. The premise of component programming is that the problem domain can be divided into discrete components, and there is only a simple method access between components to cooperate with each other. But in fact, some aspects of software are penetrating throughout the software, such as security issues, thread management, concurrency control, and more. These issues can be solved with AOP methods

转载请注明原文地址:https://www.9cbs.com/read-68449.html

New Post(0)