---------------------- ASP. NET + unity development,. Net training, and hope to communicate with you! ----------------------
I. Object-oriented 1. Differences between object-oriented and process-oriented ideas
OC is object-oriented and C is process oriented. The essence is two different ideas for solving the problem. Process-oriented focuses on steps, and object-oriented focuses on the objects needed to solve problems.
2. Common Terms
Process-oriented: Procedure oriented
Object-oriented: Object Oriented (OO)
Object-Oriented Programming: Object orientedprogramming (OOP)
3. How to create an object
Class: Describes attributes and behaviors. It is an abstract description of countless objects with the same attributes.
Object: concrete class.
4. Class Design (Step 3)
1> Class Name (naming convention: The first subtitle must contain uppercase letters, underlines are not allowed, and camper marks must be used for multiple English words)
2> attributes
3> behavior (function)
5. Classification of Classes
Nouns are generally classes. Generally, objects with the same attributes and behaviors can be abstracted into a class.
6. Example
Plants vs. botnets
Class Name: zoombie
Attribute: Life (LIFE) speed (speed) gongjili (attack power)
Behavior: Walk (walk) bite (BITE) Die (death)
Airplanes in lightning games
Class Name: Plane
Attribute: Life (LIFE) gongjili (attack force) speed (speed) bombcount (bomb count)
Behavior: fly bomb (explosion) Shoot die (death)
Ii. Classes and objects
1. Class: the class design only focuses on three things: Class Name, attribute, and method. The class Declaration uses the keywords @ interface and @ end. Class implementation using the keyword @ implementation and @ end.
2. Methods and implementations must begin with + or-
- + Class method (static method)
- -Object method (dynamic method)
3. All method scopes declared in. h are of the Public type and cannot be changed.
4. There are three common scopes of member variables:
1> @ public global access
2> @ protected can only be accessed inside the class and in the subclass.
3> @ private can only be accessed within the class
Iii. Class declaration and implementation exercises
1. Create a person class
Class declaration:
Class implementation:
Main Function
Iv. Common Errors[Email protected] @ end and @ implementation @ end cannot be nested. 2. only the declaration of the class does not implement the Class 3. write-down @ end4. declare nesting of two classes (which can disrupt the order) 5. member variables are not written in {}. 6. the method declaration is written in {}. 7. initialize the member variables of the class during declaration. Note that the member variables cannot exist independently of the object. method cannot be called as a function 9. member variables and methods cannot be modified with keywords such as static. Do not confuse them with C. 10. class implementation can be written after the mian function, and can be declared before use.
V. essential differences between OC objects and functions:
1. method implementation can only be written in @ implementation · @ end, and object method declaration can only be written in the middle of @ interface · @ end
2. All object Methods start with-and all class methods start with +.
3. Object methods can only be called by objects. Class methods can only be called by classes and cannot be called as functions.
4. the function belongs to the entire file and can be written anywhere in the file, including @ implementation · @ end, but it cannot be identified when written at @ interface · @ end, the function declaration can be performed inside the main function or outside the main function.
5. Object method category \ object all
6. function calls are independent from objects.
7. The function cannot directly access the member variable of the object through the member variable name.
VI,
Class and Method Design
Design a tool class: a calculator class that requires (1) to return π, (2) to calculate the sum of two integers, and (3) to calculate the square of an integer.
Class Declaration
Class implementation
VII. object-oriented method 1.
Object Method
1> Object Methods start with "-", for example, "-(void) xx;
2> Object methods can only be called by objects
3> access member variables of the current object in object Methods
4> call format [Object Name object method name];
2. Class Methods
1> class methods start with +, for example, + (void) put;
2> class methods can only be called by classes
3> instance (member) variables cannot be accessed in class methods, because class methods and classes are called, and no storage space is created to store member variables in the class.
4> call format: [class name class method name];
5> advantages and applicability of class methods:
The execution efficiency is higher because it does not depend on objects;
If the problem can be solved using the class method, try to use the class method;
Occasion: when the member variable is not needed inside the method, you can change it to a class method.
3.
Method Name
1> methods without Parameters
Statement:
Call:
2> methods with Parameters
Statement:
Call:
Note: The colon is also part of the method name.
---------------------- ASP. NET + unity development,. Net training, and hope to communicate with you! ----------------------
For details, see www.itheima.com.