oc--Study Notes (i)

Source: Internet
Author: User

oc--Study Notes (i)

1. Class methods

> plus start

The > class method can only be called by the class name

Cannot access member variables in the > class method

The > class method can call the class method

> Allow class methods and object methods to have the same name

the benefits and applications of class methods

> not dependent on objects , high execution efficiency

> can use class method to use class method

> When you don't need to use a member variable ( instance variable ) inside a method , You can change to a class method

2. Anonymous Objects

An object without a name is called an anonymous object [Iphone new];

object with a name : A pointer to receive the object's address called the name of the object iphone *ip = [iphone new];

Usage Scenarios for anonymous objects :

> When the object method is called only once

> Anonymous objects can be passed as actual parameters

3. Encapsulation

In the beginning it can be understood as the encapsulation of attributes, the encapsulation is actually like a washing machine, you only see the outside of the shell switch, put in how to achieve, the inside of the specific mechanical structure is encapsulated in the shell inside.

conventions :

Set method

> must be an object method (because it is set to an object member variable)

> The return value must be void

> Be sure to remove the underscore name after set open, followed by the member variable , then capitalize the first letter

> must have parameters , parameter types must be consistent with member variables

Get Method

> must be an object method (IBID.)

> must have a return value , the return value is consistent with the member variable type

> Method name direct write member variable name remove underline

> must have no parameters

Principles of Encapsulation :

Hide content that does not need to be provided externally

hides the properties , providing a common way to access them

Advantages :

can filter out some illogical data , improve the robustness of the Code

Combination Mode :

declaring pointer variables for other objects in a class

Pros : Global Object methods can be accessed , simplifying our code

cons : strong dependencies

Usage Scenarios :

when more than one method is used to the same object , set it as a member variable

How to determine whether the combination mode is reasonable :

XXX has xxx

method calls between :

class method calls the class method to

class method Call object method cannot be

The object method invocation class method can

Object method Call object method Self



This article is from the "Shangpeng Home" blog, please be sure to keep this source http://7265304.blog.51cto.com/7255304/1670882

oc--Learning Note (i)

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.