C # language-04. OOP Basics

Source: Internet
Author: User

A. OOP: Object-Oriented Thinking Class I: is a powerful data type, and is the base of the object1. Syntax: access modifiersclassClass Name {//the body of the class}              2. Member variable: does not represent a. Constant in "function": Represents a constant value associated with a class B. variable: A variable in a class C. event: A notification generated by a class that describes the occurrence What event D. Type: A local type that belongs to a class3. member functions: In the form of a. Method: Complete the operation of various calculations or functions in a class, cannot have the same name as the class, and cannot have the same name as other members of the Class B. property: Defines the values of the class and provides read and write operations to them C. Index Indicator: Allows programmers to access the array, through index indicators accessing multiple instances of the class, also known as the subscript indicator D. Operator: Defines the operator that the class object can use E. Constructor: The first function to execute when the class is instantiated is to complete the initialization of the object, and the constructor must be the same as the class name F. destructor: The last function to execute before the class is deleted, mainly to finish the end of the object, must be the same as the class name, and preceded by a "~"wavy line Symbol II".              Constructor: is a special method in a class, characterized by the same method name as the class name, no return type, and primary completion of initialization work. 1implicit constructors: By default, the system assigns a parameterless constructor to the class, and there is no method body, but be aware that once the class has a constructor, the constructor is no longer automatically assigned2. Parameterless constructor: You don't need to assign a value to a class's properties when instantiating3. With parameter constructors: When instantiating, you need to assign values to the properties of the class, and be sure to make the arguments that are passed in and the parameter list corresponding to the parameters constructor4. Method overloading: Refers to the same class where the method name is the same, and the parameter type differs from the number of arguments. In the same class, constructors and workarounds can overload III. Encapsulation: Refers to the use of abstract data types to combine data and data to form an indivisible independent entity, as far as possible to hide the internal details, only some external interface, so that the external contact, to preserve the integrity and security of the object's own data1Benefits: A. Ensuring the security of data B. Providing a clear external interface C. Class internal implementations can be arbitrarily modified without affecting other classes IV. Following Commitment: Establish the relationship between classes, realize the use of code, facilitate the expansion of the system, inheritance must conform to isA, the inherited class is called the parent class or the base class, and the class inheriting the other class is called a subclass or a derived class1The . Subclass constructor A. Implicitly calling the parent class constructor I. When you create a subclass object, the constructor of the parent class is called first, and then the constructor of the subclass itself is called, because it does not indicate which constructor to invoke the parent class , all systems implicitly call the parameterless constructor of the parent Class B. Explicitly call the parent class constructor I. byBasekeyword invokes the constructor of the parent class for initialization Ii. Note:Basewhen the keyword calls the constructor of the parent class, only the parameter III is passed. If the parent does not have a parameterless constructor, the subclass must use theBasekeyword to invoke the corresponding constructor of the parent class, otherwise the parent class does not have an argument for the reason of the parameterless constructor.2. Characteristics: A. transitivity: If a inherits B and B inherits C, then a also inherits C, and a can access the member B of C. Single root: A class cannot inherit from more than one parent at a time 3. Features: A. Inheritance simulates the real-world relationship, which emphasizes everything in OOP, which conforms to our thinking direction of object-oriented Programming B. Inheritance implements code reuse C . Inheritance makes the program structure clear, and the hierarchy of subclasses and parents is clear v. Polymorphism: the same method call can be implemented in different ways1. Use virtual methods to implement polymorphism A. Create a parent class variable, instantiate the parent class variable with a subclass object B. The parent class type is the parameter type, and its subclass object is passed in as a parameter2. The principle of substitution: subclasses can replace the parent class and appear anywhere the parent class can appear, and the behavior of the program does not change, but in turn, the parent object is a that cannot replace the subclass object. is keyword: used to check whether the object and the specified type are compatible with B. askeyword: used for type conversions between two objects3. An abstract method is a method that is not implemented, and Universal adds a keyword when defining a methodAbstractyou can declare an abstract method A. Syntax: Access modifiersAbstractreturn type method name ();                             I. Note: The abstract method does not have a closed curly brace, but instead directly follows a semicolon ";", that is, it does not include method execution logic for method body B. The virtual method differs from the virtual method Abstract methods withVirtualDecoration withAbstractmodification to use the method body, even if a semicolon does not allow the method body can quilt classOverrideMust quilt ClassOverridecan only be written in abstract classes except for sealed classes4Abstract Classes: Classes that contain abstract methods are necessarily abstract classes a. Syntax: Access modifiersAbstract classclass name; B. Abstract classes cannot be instantiated C. Abstract classes cannot be sealed or static I. Interface: interface inheritance allows for a thorough separation of the name of a method and its implementation1. Syntax: [access modifier]InterfaceInterface Name [: List of parent interface names]{//Interface Body}              2Note: A. Interface simply provides a member's declaration and does not provide a member's implementation B. Interface members can only be methods, properties, index indicators, and events, cannot be constants, fields, operators, constructors, or destructors, and cannot contain any                  Static members C. Interface member declarations cannot contain any modifiers, and interface members default access is public D. An interface is similar to an abstract base class, and any non-abstract type that inherits an interface must implement all members of the interface E. Cannot instantiate interfaces directly

C # language-04. OOP Basics

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.