1, why should there be object-oriented?
(1) Add code reuse.
(2) Reduce the maintenance burden, the unique nature of the code package, modify the program, the other does not affect each other.
2. Data encapsulation is used to solve the problem that global variables are difficult to maintain.
3. Polymorphism: In order to enhance the elasticity of inheritance, subclasses are often required to override the method of the parent class (the function name does not change).
4, abstract to reduce the maintenance burden of the updated version of the program. The provider and the user of the function are separated from each other and are independent of each other and are unaffected by each other.
5, in order to achieve the image, to provide an interface for the establishment of functional providers and users of the specification. Feature providers and users follow this specification to provide and use these features. The specification of this function is the interface. constants, function names, function parameters, and so on are defined in the interface. So the interface does not change, the function provider can arbitrarily rewrite the code in the function, without affecting the user to use these features.
Advantages of abstraction:
. Can write functions to handle classes with the same interface
For example: the payment of staff salaries: according to the position, seniority, only need to define a salary calculation interface, and then implemented separately.
. Extensions for future functionality.
. Make feature providers and users independent of each other.
6, often inherit the application in the company's internal development, to re-use other designers to write good code, and the interface is mostly used for two departments or more than two companies, for the development of their own applications when the common specifications established.
7, the class is the basic unit of data encapsulation. is the smallest unit that is reused.
Members of the class: variables, Methods, properties, events, constants
An object is a class in-memory entity that is used to describe the object's data in memory. This means that the class is used to define the object's appearance.
8, the static method can not establish the object of the class, that is, without new instantiation, and directly called by the class: Class name. Method Name ()
Static variables are typically used to configure globally shared chunks
9, Structure and class differences: The structure is mainly composed of simple numeric types, configured in the stack. The class belongs to the reference type and is configured in the heap. The structure does not support inheritance.
10. Data encapsulation: Use class for encapsulation.
Encapsulation Purpose: Data and methods are encapsulated to access data through methods. You can control how data is accessed.
11. Access modifier:
Public: All
Private: Methods and members in a class can only be used in this class and cannot be used externally.
Protected: Classes themselves can be used, subclasses can also be used. Protected is not accessed arbitrarily by derived classes, access is conditional: Access must be a subclass type when the PROTECTE member of the parent class can be accessed
Internal: Can be used in the same. NET Assembly
Protected internal: Only limited to the current project or member inherited from this class can use the
Note: In the Declaration method is, the tacit understanding private
A good object-oriented design typically defines all data members as private and then provides methods to access the data
12, the purpose of data encapsulation: easy to control data, easy to modify.
13. Static Members:
The data in the object is private, and only the object can manipulate the data, and other objects cannot manipulate it. So sometimes it's not good to keep all of the data shared by all the objects in each object, such as if all employees of a company belong to the same company, and if you define a member variable that holds the company name in the employee class, then after instantiating the object, you need to use the name of the object. Method name () to access company name information, If the company name changes, maintenance is more troublesome, and the computer also allocates memory, hard disk space, in order to solve this problem, in the implementation of this data will be placed in the global memory block, that is, the data is not the object can operate, but class-level, object operation. However, the global data is not stored in the class, so it is not possible to use the encapsulation technique of global variables, instead of statically static to describe such data. Static classes are used to describe the information that a class uses.
Static data is declared in a class, so it is possible to embody the characteristics of encapsulation. Even if the class that defines the static data is not instantiated, the static data still exists. Therefore, it is possible to manipulate static data without establishing an object entity.
The compiler automatically initializes the static variable when the class loads, that is, if the static member variable is not assigned, the compiler will automatically assign a value to the variable at compile time. The string type is an empty string, the int type is the 0,bool type is false, and the life cycle is limited to the lifetime of the application
14. Static Method:
Static methods are used to manipulate static data, and static methods belong to classes, class-level, and not object-capable, and static methods cannot use this to retain a word
Typically, compiler compiler treats static data and static methods as global variables or global functions at compile time. The default static data is private
Static methods are not able to access non-static data and non-static methods.
The main () method in a Windows application is defined as public static, and you can run main () directly without instantiating the runtime. A static method can only be called with a class, and non-static methods are invoked with an instance.
C # Object-oriented Fundamentals