1. member variables and properties
Member variables: Inside the class, private, not accessible in the main function
Property: A member variable declared in an interface that can be accessed in the main function
2. Declaration and implementation of classes
Declaration: A Declaration of a property, a class method, an object method in an interface in an. h file
Implementation: Implementation of Setter,getter methods, class methods, object methods in. m files
Private methods: Methods that do not declare a direct implementation are private methods, and private methods can only be accessed within the class
3. Prefixes
You can enhance the degree of differentiation and be careful to maintain a good prefix style.
4. Encapsulation, inheritance, polymorphism
Encapsulation: Process-oriented is the dog eats excrement, object-oriented eating (dog, excrement). Object-oriented is to encapsulate this action in a way that allows other objects to be used or to eat other things. This allows the method to be reused many times, greatly simplifying the programming process. Object-oriented thinking is to encapsulate a method on a large frame. The process-oriented idea is also used in local method realization.
Inheritance: Subclasses inherit the parent class and can inherit properties and methods from the parent class. Inheritance can reduce the duplication of code, improve the efficiency of operation, can improve the readability and maintainability of code, can play the role of method scheduling. Multiple inheritance is not supported in OC, but similar functionality can be accomplished through categories and protocols.
Superclass superclass, subclass subclass, override method overrides
Polymorphic: Allows the name of the method (the subclass overrides the method of the parent class), the parameter or return value can be the parent type's incoming and returned (different objects respond differently to the same message). Method of rewriting (to understand the importance of invoking [super's method name] When re-rewriting is a good idea).
5. Sending messages and calling methods
Message is the working mechanism of OC, according to the name of the message sent to find the corresponding method, the call method is the last step to send a message.
6. Code specification
Plus spaces on both sides of the equals sign
Class method, beginning of object method)-+ followed by a space
A piece of code a paragraph to keep the code neat and concise
7. Class methods
Instantiation method (Factory method): Constructs a new instantiated object (format: Class Name: With property name: and property name:) while assigning a value
Class method: Executed directly by the class in which he resides
8.super and Self keywords
Super plaintext invokes the logic of the method of the parent class with the same name, the caller or the object itself
Self is a pointer to the first address of the object, who calls the method where self is located.
Self represents the current object in the-method, and this class is represented in the + method.
9. Aggregation and Combination
When designing a class, you need to distinguish between composition and aggregation. A person and his hand is a combination of the relationship between the geese and geese is the aggregation of the relationship. A good composite relationship will give programmers the right idea when coding.
The composite relationship represents the has a
The inheritance relationship represents the is a
Distinguishing between composition and inheritance is an important principle for beginners in designing classes, and this principle is also the correct approach under the guidance of cohesion-poly-low-coupling thought.
[email protected] and #import
Importing class names in. h files using @class can simplify dependencies between files and reduce coupling.
Importing class names in. h files can easily confuse dependencies between files
@class xxx: Tell compiler xxx is a class, as to what the class has methods and properties, here do not check
OC's Learning Summary 1