O ' C Foundation first day classes and objects

Source: Internet
Author: User

1. How to use object-oriented thinking in the code to solve the problem.

A. Do not take 1 steps to achieve it yourself.

B. First look for 1 people who have no ready-made special to do this thing. Framework.

If there is a person in the frame shouting directly to use it.

C. If not in the framework? Build yourself 1 people who have this function.

This person can be used not only in this place but also in other places.

2. Object-oriented relative to process oriented.

Object-oriented advantages: the maintenance and extension of the late program is very convenient. If the function changes we just need to change 1 people.

OC Swift Java C # ...

Process-oriented advantages: the interaction with the underlying is highly efficient.

C

3. Classes and objects.

1). What is an object

object is the concrete existence in real life.

Features: can be used to see, touch and take.

2). What is a class

Birds of a feather flock together.

A class is a general term for a thing that has the same characteristics and behavior on 1 groups.

Features: Abstract, cannot be used directly.

Person. is not a single point of 1 individuals. It means 1 groups.

Students. is 1 people and has a learning behavior.

The class cannot be used directly because the class is a 1 collectively.

If you have to use it. It is necessary to find the 1 specific existence of this group of things.

3). Food.

Fruit.

Apple.

Red Fuji apples.

4). Transportation.

Car.

Car

Mercedes Benz Car

Mercedes Benz Car CLS350

4. Class-To-object relationships

A class is a template, and objects are created from this template. There is nothing in the template that will be more or less.

Class is a mold for making moon cakes, so classes cannot be used. So the mold is not edible.

The object is a mooncake made from this mold. What is on the die on the moon is not likely to be more or less.

Objects are available for immediate use. Mooncakes can be eaten.

As long as there are 1 of the production of moon cakes can be made according to this mold a lot of moon cakes out.

As long as there are 1 class templates, then we can create many and many objects.

5. How to design 1 classes.

The most three points:

This class is called a name. What kind of things do you want to describe?

This type of thing has the same characteristics.

The same behavior as this kind of thing

People

Features: Name Age Height weight gender

Behavior: Eat to sleep walk

Air conditioning:

Features: Brand color size power count weight ...

Behavior: Let the air cool off the heat

6. How to find the class: the noun refinement method.

Analyzing the requirements, the nouns that appear are classes. Then analyze the three elements of the class.

3 Tanks fired 6 shells and hit 2 planes.

Tank class

Features: Model size attack capability. Color...

Behavior: driving a projectile

Shell class

Features: Model power .....

Behavior: Flight explosion

Aircraft class

Features: Model size number of seats ....

Behavior: Flight explosion.

Xiao Ming is holding 1 dogs with hot dogs in the bus.

Human

Features: Name age ....

Behavior: Walking the Dog

Bus

Features: Model seat number ....

Behavior: Driving ...

Hot dog

Characteristics: Taste. Size.....

Behavior: Smells.

Dog.

Features: Color variety ...

Behavior: Pick up a hot dog.

7. Design 1 classes. The most important is the three elements of a class.

Class Name:

Characteristics:

Behavior:

8. Is there a class or a first object?

From a realistic point of view: There must be an object before the class

From the point of view of code: must be the first class and then have objects.

Code:

Create a class template first. You can then create objects from this template to use.

Use classes to describe 1 of things and then create objects from the class template.

9. How to define a class

1). What does the class do? Describe a group of things that have the same characteristics and behavior.

2). The definition class is divided into two parts.

A. Declaration of the class.

@interface Class Name: NSObject

{

Write about the common characteristics of such things;

}

Write statements about the common behavior of such things.

@end

B. The implementation of the class.

@implementation class Name

Write about the realization of the common behavior of such things.

@end

C. Specific practices.

Define the same characteristics of such things as variables defined in the braces of the Declaration class.

D. Define the specification of the class.

The first letter of every 1 words of the class name is capitalized.

A variable name that shows the common characteristics of such things must begin with an underscore.

10. Create the object.

1). Class is not directly available. If you want to use it, you have to find the 1 specific existence in this class.

2). This specific existence has all the members of this class definition.

3). How do I create an object of a class?

Class Name * Object name = [class name new];

Person *P1 = [person new];

Represents the creation of 1 objects. The object name is called P1.

The P1 object is created from the person template.

So

The P1 object has all the things defined in the person template.

P1 is an object so we can use P1 directly.

4). Variables used to describe the common characteristics of such things.

Called member variables, instance variables, fields, properties.

11. Accessing the members of an object

A. By default, members in an object have no access to the outside world.

If the outside world wants to access then write 1 @public keywords on top of the field of the class.

B. Accessing the syntax of an object's members

Object name, member name = data;

(* object name). member name;

12. Please define 1 classes of students.

Attribute: The name of the age school number results.

Define the class and then create the object. and assigns a value to the object's properties.

Finally, the values of the individual properties of the object are output.

13. Talk a few more questions again

1). What does the class do for?

Used to describe a group of things that have the same characteristics and behavior.

14. Several issues to note

1). Locate the position. The Declaration and implementation of a class are directly within the source file and should not be written inside the function.

2). Capitalize the first letter of every 1 words in the class name.

3). What does nsobject mean not to need a tube. The middle of the class name and NSObject is separated by colons.

4). Instance variables used to describe the common characteristics of such things should be written in the parentheses of the declaration of the class.

5). The instance variable name must begin with an underscore.

6). Class divided into two parts can be divided into declarations and implementation.

@interface is a statement

@implementation is implementation.

7). It is necessary to declare or implement @end.

8). The implementation of the class must be followed by the declaration of the class

9). If you find that the member is removed by the object name arrow, then it means no write @public

O ' C Foundation first day 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.