Classes and objects

Source: Internet
Author: User



"Process-oriented language"
1, the CPU is the unit that receives the message, it completes all the operation of the data (storage and operation)
2, is the mapping of mathematical logic

"Object-oriented language"
1, the object is to receive the message unit, an object to complete a function, a number of objects work together,
The modularity of the function is very high.
2, is the Life logic mapping

OBJECTIVE-C, abbreviation OC
1. OC is fully compatible with C
2, OC is the extension of C, is a superset of C
3. Extended object-oriented support

Difficulty: Protocol, agent, memory management

First, recognize classes (Class) and objects (object)
1. From the logic of life
Class object
Mr Li, the prime Minister of Human learning
Cat Garfield Tom
Computer, my computer, your computer.

2, from the angle of the package
"Struct" is the encapsulation of the structure of the stored data
A "function" is the encapsulation of a method that processes data
A "class" is a wrapper over the structure of the stored data while encapsulating the method that processes the data

3, from the perspective of programming language
Class: Is a custom data type
Object: is a variable of a class type

4. From the official definition
Class: Abstraction of things with the same attributes (attributes and behaviors)
Object: The figurative of a class

Second, the use of the class
Foundation.h contains almost all of the usual C header files
#import Import header file to automatically filter for duplicate inclusion issues

1. Definition
@interface Jyclass:nsobject
: Represents an inheritance relationship (subclass: Parent Class)
NSObject is an official class, which is the direct or indirect parent class of all classes
Only it has no parent class, it is also called the root class
{
Here declare member variables, instance variables, object properties, also called fields in OC
int _a;
}
Declare member methods here, member functions, also called messages in OC
Print the value of the _a
void PrintA;
-(void) PrintA;
@end

2. Realization part
@implementation Jyclass
-(void) PrintA
{
NSLog (@ "_a =%d", _a);
}
@end

2. Method invocation
[Object pointer/receiver method/message]

Third, other grammar
1. Creation of classes
A, the project column
B, navigation bar

Command + control +?? /?? : Switches the interface and implementation of a class
The project directory in Xcode is different from the disk directory

2. Construction method
Function: For object initialization
1. Methods to create automatic calls to objects
2, all the methods in OC that begin with INIT are construction methods and need to be called manually

Self: A pointer to the current object, who calls the method, and self indicates who
Super: Is the keyword that invokes the parent class method

[[Jyhuman alloc] init] <==> [Jyhuman new]

Exercises:
1, define a mathematical class, there are two member variables, a, B,
The method has variable settings and subtraction.
2, define a cube, the method has a long and wide height setting, volume calculation
3, Xiao Ming has two cards in his hand, the left ♠? A, right hand?? K, after asking for the exchange of hands,
What are Xiaoming's hands?
4, create a car, properties have speed,
Writing the construction and set methods for speed
5, create a road, the property has length,
Writing construction methods and set methods for length
6, create a postcard class,
Properties: Name, unit, phone number, QQ
Method: Constructs the method, sets the name, the unit, the telephone number, the QQ,
Related information to print.




Classes and objects

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.