`
jason_zh
  • 浏览: 8257 次
  • 性别: Icon_minigender_1
  • 来自: 大连
最近访客 更多访客>>
社区版块
存档分类
最新评论

Objects,Messages,Classes

阅读更多
Objects:

As the name implies, object-oriented programs are built around objects.
An object associates data with the particular operations that can use or affect that data.
In Objective-C, these operations are known as the object’s methods; the data they affect are its instance variables.

In Objective-C, objects are identified by a distinct data type, id.This type is
defined as a pointer to an object
////id anObject;///
nil -->objc.h@/NextDeveloper/Headers.

Messages:

To get an object to do something, you send it a message telling it to apply a
method. In Objective-C, message expressions are enclosed in square brackets:
[receiver message]

(30.0, 50.0):==> [myRect setOrigin:30.0 :50.0];
setWidth:height: ==> [myRect setWidth:10.0 height:15.0];
[receiver makeGroup:group, memberOne, memberTwo, memberThree];

Classes:

In Objective-C, you define objects by defining their class. The class definition
is a prototype for a kind of object; it declares the instance variables that become part of every member of the class, and it defines a set of methods that all objects in the class can use.

NSObject --> NSObject, being a root class, doesn’t have a superclass. In OpenStep, it’s in the inheritance path for every other class.
int i = sizeof(Rectangle);
Rectangle *myRect;
if ( [anObject isMemberOfClass:someClass] )
if ( [anObject isKindOfClass:someClass] )
id aClass = [anObject class];
Class aClass = [anObject class];
Creating Instances=> [Rectangle alloc]
The alloc method dynamically allocates memory for the new object’s instance
variables and initializes them all to 0—all, that is, except the isa variable that
connects the new instance to its class.

Defining A Class:
In Objective-C, classes are defined in two parts:
interface=>
@interface ClassName : ItsSuperclass
{
instance variable declarations
}
method declarations
@end
class methods ->+ alloc;
instance methods -> - (void)display;
- (float)radius;
- (void)setWidth:(float)width height:(float)height;
- makeGroup:group, ...;
Importing the Interface -> #import "Rectangle.h"
Referring to Other Classes -> @class Rectangle, Circle;
An interface file mentions class names when it statically types instance variables,return values, and arguments.
The Implementation=>
@implementation ClassName : ItsSuperclass
{
instance variable declarations
}
method definitions
@end
@private The instance variable is accessible only within the class that declares
it.
@protected The instance variable is accessible within the class that declares it
and within classes that inherit it.
@public The instance variable is accessible everywhere.

How Messaging Works:
[receiver message]->objc_msgSend(receiver, selector)

分享到:
评论

相关推荐

    Softgroup Components.NET Subclass and Hook Objects v2.0.3870

    Softgroup .NET Subclass and Hook Objects supply .Net fast, small and lightweight wrapper classes that made easy and secure subclassing and hooking windows for any programmers. Included Classes ...

    python3.6.5参考手册 chm

    PEP 3155: Qualified name for classes and functions PEP 412: Key-Sharing Dictionary PEP 362: Function Signature Object PEP 421: Adding sys.implementation SimpleNamespace Using importlib as the ...

    javaee API

    javax.enterprise.deploy.shared Provides shared objects for Tool Vendor and Product Vendor implementation classes. javax.enterprise.deploy.shared.factories Provides shared factory manager object for ...

    Objective-C Programming: The Big Nerd Ranch Guide (2nd Edition)

    - Objects, classes, methods, and messages - Pointers, addresses, and memory management with ARC - Properties and Key-Value Coding (KVC) - Class extensions - Categories - Classes from the ...

    iOS 4 编程(英文版)

    3. Objective-C Objects and Messages 4. Objective-C Classes 5. Objective-C Instances 6. Anatomy of an Xcode Project 7. Nib Management 8. Documentation 9. Life Cycle of a Project 10. Cocoa Classes 11. ...

    ObjCRuntimeGuide

    Static components include the definition of classes and methods, while dynamic interactions involve sending messages to objects. The `NSObject` class plays a central role in this interaction, as it ...

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 75: Include failure-capture information in detail messages Item 76: Strive for failure atomicity Item 77: Don’t ignore exceptions 11 Concurrency Item 78: Synchronize access to shared mutable ...

    ProgrammingWithObjectiveC

    #### Classes Are Blueprints for Objects 类是用于创建对象的模板或蓝图。每个类定义了一组属性和方法,这些属性和方法定义了该类的对象的行为和状态。 #### Mutability Determines Whether a Represented Value ...

    Get Programming - Learn to code with Python.epub

    Lesson 9 - Simple error messages Lesson 10 - Tuple objects: sequences of any kind of object Lesson 11 - Interacting with the user Lesson 12 - Capstone project: name mashup UNIT 3 - MAKING DECISIONS ...

    Professional.MFC.with.VC6

    The Foundation Classes MFC Source Code Header Files MFC Libraries Summary Chapter 2: The Wizards and The Gallery AppWizard Starting AppWizard Choosing Your Application's User Interface ...

    软件工程第九章-面向对象方法学引论PPT课件.ppt

    面向对象方法学可以用下列方程来概括:OO=objects+classes+inheritance+communication with messages。面向对象就是既使用对象又使用类和继承等机制,而且对象之间仅能通过传递消息实现彼此通信。 面向对象方法学有...

    软件工程面向对象方法学概述.pptx

    4. 面向对象方法可以用一个公式概括:OO = Objects + Classes + Inheritance + Communication with messages,即对象、类、继承和消息通信是面向对象方法学的基础。 面向对象方法学有多个显著的优点: 1. 它与人类...

    Java并发编程-Doug Lea

    Autonomous loops, oneway messages, interactive messages, cancellation Concurrent application architectures Flow, parallelism, layering Libraries Using, building, and documenting reusable concurrent ...

    programming with objective c

    #### Classes Are Blueprints for Objects 类是创建对象的蓝图。它们定义了对象的属性和方法。类的设计是面向对象编程的核心部分。 #### Mutability Determines Whether a Represented Value Can Be Changed 可变...

    SAP PI Handbook 71

    - **Proxy Generation**: Generating proxy classes for client-side communication. - **Defining Mappings**: Creating mappings to transform messages between different formats. - **Using Predefined ...

    Synopse mORMot Framework 1.8 with help

    Due to its modular design, switch from such a Client-Server architecture over HTTP, named pipes or GDI messages into a stand-alone application is just a matter of mORMot classes initialization. ...

    Java邮件开发Fundamentals of the JavaMail API

    the ability to see how many new mail messages they have, are not supported by POP at all. These capabilities are built into programs like Eudora or Microsoft Outlook, which remember things like the ...

    Perl 6 Fundamentals: A Primer with Examples, Projects, and Case Studies

    classes and objects; regexes; and code testing. When you’ve mastered the basics, Perl 6 Fundamentals moves onto more advanced topics to give you a deeper understanding of the language. You’ll learn...

Global site tag (gtag.js) - Google Analytics