Geek College C # video tutorial materials recommended

Source: Internet
Author: User
Tags traits
The Geek's College C # video Tutorial is an introductory course in the C # language, which will be taught from. NET platform and the basic concepts of C #, in-depth introduction to the basic syntax of C # development, simple program logic, the use of Visual Studio Tools, and the implementation of commonly used algorithms. At the same time, we hope to help the small partners quickly step into the gate of the C # language through exercises related to the course and programming exercises.

Course Play Address: http://www.php.cn/course/243.html

The teacher's lecture style:

Teachers teach in a clear, well-organized, layered analysis, interlocking, rigorous argumentation, structural rigorous, with the logical power of thinking to attract students ' attention, with reason to control the course of classroom teaching. By listening to the teaching of teachers, students not only learn knowledge, but also receive the training of thinking, but also by the teachers rigorous study attitude of edification and infection

The difficulty in this video is the C # Object-oriented feature:

I. Encapsulation: We can look at anything in the world as an object, so here we take people for example, a person must be an object. So what is encapsulation? Encapsulation is the person who wants to accomplish one thing, all the tools he needs are on his own, and all the technology he needs is in his head. You can accomplish this without the help of others. What good is this? The advantage is that if I want to command this person to do one thing, I don't need to know how he is done, and he doesn't need to help him to finish it, as long as he knows the result, he is OK. As for what he did after what I did not intervene, which helped him to better do the job faster, I myself also easy.

1. Access Rights (visibility)

Public: (Everywhere) all packages, classes are visible after importing the common

Protected: (Legal inheritance) itself, the subclasses of the different packages themselves,

Private: (selfishness) only visible in this class

2.

(1), attribute-->private (private attribute, public method, without default)

(2), Method--public protected

The written explanation is as follows: Each object contains all the information it needs to operate, so the object does not have to rely on other objects to do its work.

Second, inheritance: think of people as an example, each of us will have some common characteristics, all have to do something the same thing. For example: People have a head, two arms, two feet, this is a common feature. All have to eat, drink water, this is to do the same thing. So if we're going to declare a lot of individuals now and everyone has these traits, then I'm not going to write a lot of repetitive code? So we can first build a person's parent class, the parent class does not represent a specific person, but a virtual person with all the common characteristics of the person. The next time we are going to instantiate a specific person, we just have to inherit this person from the "virtual Man" above, then he has all the common traits of man. In this way, we can not write the duplicated code.

Of course, the goal of inheritance is not just to save code, but to implement the polymorphic functionality behind it. Beginners only need to understand the inheritance can write a lot less code, the rest of the need to slowly understand the project.

The written explanation is as follows: The inheritance of an object represents a "is-a" relationship, and if two objects A and B can be described as "B is a", then B can inherit from a.

Note: If a inherits B, then a does not only have all the characteristics of B except for the private property, a can also have its own unique characteristics. For example, the above example, a successor to the "virtual person", then he has a head, two arms, two feet, to eat water, he may also be programmed. Programming is his unique feature, because not everyone will be programmed.

1.

(1), continuation: The parent class exists, the subclass is not rewritten but can be used;

(2), added: Parent class not, subclass New added

(3), rewrite: The parent class subclass all exists, but Fred does not satisfy wants, the subclass carries on the new definition to it;

2. Instantiation:

(1), the late father class after the sub-category, first static after the member;

The instantiation of the parent class is called when the static construct is fast, the constructor of the parent class is called, and then the construction block of the subclass, in the calling subclass of the constructor method;

(2), the default call to the parent class empty structure;

3. Overriding override

(1), Overrides and overloads:

Overriding: Inheriting subclasses, method signatures are the same (method name + parameter number type Order)

Overloading: Same class method name, parameter number type Order

(2), rewrite rules: In the subclass of the signature is the same as the parent class, in a reasonable range to improve the visibility of the child class;

A, return type: the base type and void must be the same; reference type to <= the return class of the parent class

B, Exception:

C, Visibility: to be greater than or equal to the overridden method in the parent class

Three, polymorphic: There are many states must have inheritance, only a number of classes inherit the same class at the same time, there are many states such a statement.

Or a man-made example, before we have said that people have to do "eat" such a thing. "Eat" this thing, reflected in the class is the method. Because it is people are to do, so we in the "virtual person" in writing this method, but everyone has a different way to eat, useful chopsticks also useful fork, have to eat rice also have to eat pasta. So if we're going to describe the process of eating different people, we're going to put this process into a specific subclass, because everyone is not the same. In the same way, subclasses have different implementations, and this is polymorphic, and polymorphism helps the program to be flexible.

Note: If you override the method (Polymorphic) of the parent class in the subclass, the method in the parent class will no longer be called.

1. Benefits:

simplifies the programming interface. It allows for the reuse of some habitual naming between classes and classes without naming a new name for each new function.

Simplifying code

If the type of the parent class is used in a function/method parameter, you can pass in the object of the parent class, the child class

Limitation: A variable of a parent class type that cannot directly invoke a method specific to a subclass. You must strongly convert to a variable of subclass type to directly invoke a method specific to a subclass

2, compile-time polymorphism: is actually overloaded, is to non-virtual members, the system at compile time, according to different signatures to decide what to do.

3, run-time polymorphic: That is, rewrite, is through the virtual member implementation, refers to the system until the operation, based on the actual situation to determine what kind of operation.

It's easy to understand the first situation, and different signatures have different implementations.

The second case is implemented on the basis of inheritance, when the subclass inherits the base class, by rewriting the virtual member, then using the base class to refer to the subclass object, the different subclass objects implement the corresponding operation.

The benefit is obvious, with the base class type defined once, and then passed to it a different subclass object, then achieve different operations, improve efficiency.

Related Article

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.