Objective C. Основан на C Объектно-ориентированный Использует сообщения Динамический Протоколы Интроспекция.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

Objective-C Lecture 2 Memory management Memory management in OC is semi- automatic: The programmer must allocate memory for objects either a) explicitly.
1 Objective-C and Object-Oriented Programming. 2 Introduction Objective-C is implemented as set of extensions to the C language. It's designed to give.
Lecture 3 - Writing Initializers A correct initializer must comply with the following: The initializer name should begin with init The initializer returns.
Black Jack in Objective-C
Object Oriented Programming with Java
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
suppose you had Bumblebee, Jet, and Bird classes. All three, although unrelated, implement the flying behavior, and so you could say they are each a Flyer.
Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Object Oriented Programming
Rapid GUI Programming with Python and Qt Classes and Modules By Raed S. Rasheed Classes and Modules By Raed S. Rasheed 1.
Classes and SubClasses Super Parent Sub Child IS - A.
Exercises on Basic OOP TCP1201: 2013/2014. Catch the Bug 1 class Point { private : int x, y; public : Point(int u, int v) : x(u), y(v) { } int getX()
Based on examples in "Programming in Objective-C," Copyright © 2004 by Sams Publishing O BJECTIVE -C Q UICK & D IRTY.
CS 3800 Su 11 Beg. IOS Dev L4 Obj C part 1 CS 3800 Introduction to IOS programming Summer 2011 G. Zimmerman.
Lecture 28: Abstract Classes & Inheritance Announcements & Review Lab 8 Due Thursday Image and color effects with 2D arrays Read: –Chapter 9 Cahoon & Davidson.
Chapter 12: Support for Object-Oriented Programming
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
IPhone Development Crash Course By Dylan Harris
© Copyright Eliyahu Brutman Programming Techniques Course Version 1.0.
IPhone 101. Outline Objective-C Random bits of the API Using the simulator Debugging with Xcode.
CSE S. Tanimoto Java Classes and Inheritance 1 Java Classes and Inheritance Object (again): A computational unit consisting of some data elements.
1 Introduction to Objective-C and iPhone Development.
Intro to Objective-C Syntax: What’s most confusing about Objective-C? Most class names start with NS: NSString, NSObject Parameter lists are not comma.
UML Class Diagram: class Rectangle
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
Objective-C Quinton Palet. Introduction  Objective-C was developed to bring large scale software development the power of the object-oriented approach.
Memory Management and Automatic Reference Counting/ Copying Objects Archiving Copyright © 2012 by Yong-Gu Lee
More on Classes Inheritance Copyright © 2012 by Yong-Gu Lee
Object Oriented Programming
Objective-C First Part adapted from a presentation by Kevin Layer.
Objective-C OOP Spring OOP Conceptually the same as C++, Java, and all other object oriented languages The syntax, however… …is, well, different.
1 Introduction to Objective-C Programming (Level: Beginner) Lecture 1.
Objective-C1 CS151 Presentation: Objective C Kai Tai Pang William Sze.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Passing data between storyboard views Singleton pattern.
Objective-C Memory management Memory management is semi-automatic: The programmer must allocate memory for objects either a) explicitly (alloc) or b) indirectly.
Chapter 10 Inheritance and Polymorphism
Lecture 06 Java and OOP Jaeki Song. Outlines Java and OOP –Class and Object – Inheritance – Polymorphism.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
Constructors & Destructors, Proxy Classes, Friend Function and example of static member.
Lec 5 Obj-C part 2 CS 3800 Introduction to IOS programming Lecture 5 Summer 2011.
OBJECTIVE C Kurt Ladendorf. General Knowledge  Super set of C  Smalltalk  Mainly used for iOS and other Apple development.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CHAPTER 7 Object Oriented Programming. Object-oriented program “Data and Operations go together was independently” is the main idea The promise of making.
Copyright 2005, The Ohio State University CSE – Introduction to C++ Name: Shirish Tatikonda Time: T 3:30 PM Room: BE 394
Class Inheritance. The biggest advantage of object oriented design is that these objects can be repeatedly used and redefined as needed. As programmers,
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Objective-C: Intro Michelle Alexander COMS E6998 2/4/2013.
Interfaces & Abstract Classes (For CS III AP) March 2014.
Static Variables. Function Scope  “Normal” local variables go out of scope and are deallocated when a function terminates.
Java Yingcai Xiao.
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
classes and objects review
UML Class Diagram: class Rectangle
Modern Programming Tools And Techniques-I Inheritance
null, true, and false are also reserved.
Pointers, Dynamic Data, and Reference Types
EEC-492/693/793 iPhone Application Development
Announcements & Review
Programming and Debugging
Java Classes and Inheritance
Java Classes and Inheritance
Java Classes and Inheritance
An Example of Inheritance
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

Objective C

Основан на C Объектно-ориентированный Использует сообщения Динамический Протоколы Интроспекция

id Специальный тип, являющийся указателем на произвольный объект. [receiver message]; nil может принимать любые сообщения, возвращает тоже nil

Сообщения [myRect setOrigin:30.0 :50.0]; [myRect setWidth:10.0 height:20.0]; [myObject makeGroup: obj1, obj2, obj3, obj4, nil]; [myRect setColor:[otherRect color]]; [Rect newrect]; Rect *rect = [Rect new];

Создание новых ClassName : SuperClass { instance variable declarations } method

@interface Rect : NSObject { float width; float height; BOOL isFilled; NSColor * color;

@interface Rect : NSObject { float x, y; float width; float height; BOOL isFilled; NSColor * color; } + newRect; - (void) display; - (float) width; - (float) height; - (float) area; - (void) setWidth: (float) theWidth; - (void) setHeight: (float) theHeight; - (void) setX: (float) theX y: (float)

#import Rect + newRect { Rect * rect = [[Rect alloc] init]; [rect setWidth: 1.0f]; [rect setHeight: 1.0f]; [rect setX: 0.0f y: 0.0f]; return [rect autorelease]; } - (float) width { return width; } - (float) height { return height; } - (float) area { return [self width] * [self height]; } - (void) setWidth: (float) theWidth { width = theWidth; } - (void) setHeight: (float) theHeight { height = theHeight; } - (void) setX: (float) theX y: (float) theY { x = theX; y = theY;

@interface Worker : NSObject { char * int age; char * int job; float id boss }

Как работают сообщения [object msg] -> objc_msgSend id objc_msgSend(id theReceiver, SEL theSelector,...) object -> isa -> class object -> superclass, dispatch table

Селекторы SEL setWidth SEL setPos SEL setWidth = NSSelectorFromString ); NSString * methodName = NSStringForSelector ( setPos ); if ( [anObject ) [anObject setWidth:1];

self super

ProtocolName Serializable - (id) initWithCoder: (NSCoder *) coder; - (void) encodeWithCoder: (NSCoder *)

MyProto if ( [myObject (Serializable)] ) [myObject encodeWithCoder: myCoder]; id myObject; Shape *myObject;

Создание и уничтожение объектов id anObject = [[Rectangle alloc] init]; id anObject = [Rectangle alloc]; [anObject init]; id anObject = [Rectangle new];

init - initWithName: (const char *) theName // designated initializer { [super init]; // call inherited method name = strdup ( theName ); } - init { return [self initWithName: ""]; }

retain, release id object = [MyClass new]; … [object release]; id object = [[object getResult] retain]; … [object release];

dealloc - (void) dealloc {... [super dealloc]; }

NSAutoreleasePool NSAutoreleasePool *pool = [NSAutoreleasePool new]; … [pool release];

autorelease + (Rect *) newRect { Rect *rect = [Rect new]; [rect autorelease]; return rect; }