Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Objective C: Presented By: S.Upendhar 07891A0565

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 41

OBJECTIVE C

Presented By :
S.Upendhar
07891A0565
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
11.Conclusion
CONTENTS :
1.Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
INTRODUCTION
Objective-C is implemented as set of

extensions to the C language.
It's designed to give C a full capability for

object-oriented programming, and to do so
in a simple and straightforward way.
Its additions to C are few and are mostly

based on Smalltalk, one of the first
object-oriented programming languages.
CONTENTS :
1. Introduction
2.History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
HISTORY
Objective-C was invented by two men, Brad Cox and
TomInventors
Love.
Both were introduced to Smalltalk at ITT in 1981
Cox thought something like Smalltalk would be very
useful to application developers
Cox modified a C compiler and by 1983 he had a
working Object-oriented extension to C called OOPC.
HISTORY (Cont.)

Tom Love acquired a commercial copy of Smalltalk-80


whileDevelopment
working for Schlumberger Research
With direct access Smalltalk, Love added more to
OOPC making the final product, Objective-C.
In 1986 they release Objective-C through their
company “Stepstone”
HISTORY (Cont.)
 In 1988 Steve Jobs acquires Objective-C license for NeXT
 UsedNeXT and NeXTSTEP
Objective-C to build the NeXTSTEP Operating System
 Objective-C made interface design for NeXTSTEP much easier
 NeXTSTEP was derived from BSD Unix
 In 1995 NeXT gets full rights to Objective-C from Stepstone
HISTORY (Cont.)
Developed in 1993 by NeXT and Sun
The OPENSTEP API
An effort to make NeXTSTEP-like Objective-C
implementation available to other platforms.
In order to be OS independent
• Removed dependency on Mach Kernel
• Made low-level data into classes
Paved the way for Mac OS X, GNUstep
HISTORY (Cont.)
NeXT is taken over by Apple in 1996 and put Steve
JobsAPPLE
and hisand
Objective-C
Mac OS Xlibraries to work
Redesigned Mac OS to use objective-C similar to that
of NeXTSTEP
Developed a collection of libraries named “Cocoa” to aid
GUI development
Release Mac OS X (ten), which was radically different
than OS 9, in March 2001
HISTORY (Cont.)
 Primarily the most frequently used frameworks nowadays.
The COCOA API
 Developed by Apple from NeXTSTEP and OPENSTEP

 Has a set of predefined classes and types such as NSnumber,


NSstring, Nsdate, etc.

 NS stands for NeXT-sun

 Includes a root class NSObject where words like alloc, retain, and
release come from
CONTENTS :
1. Introduction
2. History
3.Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
WHY OBJECTIVE C ?
Objective-C incorporates C, you get all the benefits of C
when working within Objective-C.
You can choose when to do something in an object-
oriented way (define a new class, for example) and when
to stick to procedural programming techniques (define a
structure and some functions instead of a class).
Objective-C is a simple language. Its syntax is small,
unambiguous, and easy to learn
Objective-C is the most dynamic of the object-oriented
languages based on C. Most decisions are made at run
time
WHY OBJECTIVE C ? (Cont.)

The Objective-C language is fully compatible with


ANSI standard C
Objective-C can also be used as an extension to C++.
Although C++ itself is a Object-Oriented Language,
there are difference in the dynamic binding from
Objective-C
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4.ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
ID
id is a data type used by Objective-C to define a pointer of an
object (a pointer to the object’s data)
Any type of object, as long as it is an object, we can use the id
data type.
For example, we can define an object by:
id anObject;
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5.Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
DYNAMIC TYPING
 id data type has no information about the object

 Every object carries with it an isa instance variable that


identifies the object's class--what kind of object it is

 Objects are thus dynamically typed at run time. Whenever it


needs to, the run-time system can find the exact class that an
object belongs to, just by asking the object
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6.Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
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]
 The receiver is an object. The message is simply the name of a
method and any arguments that are passed to it
MESSAGES (Cont.)

For example, this message tells the myRect


object to perform its display method, which
causes the rectangle to display itself
[myRect display];

[myRect setOrigin:30.0 :50.0];

The method setOrigin::, has two colons, one


for each of its arguments. The arguments are
inserted after the colons, breaking the name
apart
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7.Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
POLYMORPHISM
Each object has define its own method but for
different class, they can have the same
method name which has totally different
meaning
The two different object can respond
differently to the same message
Together with dynamic binding, it permits you
to write code that might apply to any number
of different kinds of objects, without your
having to choose at the time you write the code
what kinds of objects they might be
INHERITANCE
 Root class is typically NSObject

 Inheritance is cumulative. A Square object has the methods and


instance variables defined for Rectangle, Shape, Graphic, and
NSObject, as well as those defined specifically for Square
INHRITANCE (Cont.)

Instance Variables: The new object contains not only


the instance variables that were defined for its class,
but also the instance variables defined for its
superclass, all the way back to the root class
Methods: An object has access not only to the
methods that were defined for its class, but also to
methods defined for its superclass
Method Overriding: Implement a new method with the
same name as one defined in a class farther up the
hierarchy. The new method overrides the original;
instances of the new class will perform it rather than
the original
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8.Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
INTERFACE & IMPLEMENTATION
Compiler creates one class object to contain
Class Objects
the information for the name of class and
superclass
To start an object in a class:
id myRectx; myRect = [[Rectangle alloc] init];

The alloc method returns a new instance and that


instance performs an init method to set its initial state.
INTERFACE & IMPLEMENTATION
In Objective-C, classes are defined in two parts:
Defining a Class
• An interface that declares the methods and instance
variables of the class and names its superclass
• An implementation that actually defines the class
(contains the code that implements its methods)
INTERFACE & IMPLEMENTATION
 The declaration of a class interface begins with the compiler directive
The Interface
@interface and ends with the directive @end

@interface ClassName : ItsSuperclass

instance variable declarations

method declarations

@end
INTERFACE & IMPLEMENTATION
 Instance Variables:
Declaration
float width;

BOOL filled;

 Methods:
o names of methods that can be used by class objects, class methods, are preceded by a
plus sign
o methods that instances of a class can use, instance methods, are marked with a minus
sign
INTERFACE & IMPLEMENTATION
 Importing the Interface: The interface is usually included with
the #import directive
#import "Rectangle.h"

 To reflect the fact that a class definition builds on the definitions of inherited
classes, an interface file begins by importing the interface for its superclass
 Referring to Other Classes: If the interface mentions classes not in this
hierarchy, it must declare them with the @class directive:
@class Rectangle, Circle;
INTERFACE & IMPLEMENTATION
#import "ClassName.h"
The Implementation
@implementation ClassName
method definitions
@end
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9.Objective C vs. C++
10.“Objective C”
OBJECTIVE c vs. C++
 Adds OOP, metaprogramming and  Has numerous uses
generic programming to C
 Large and complex code for OOP
 Only adds OOP to C
 Comes with a std library

 Has no standard library; is


dependant on other libraries

 Mostly used for application


building

 Simpler way of handling classes


and objects
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
“OBJECTIVE C”
 It's designed to give C a full capability for object-oriented programming

 Objective-C source files by a ``.m'' extension

 “.h” file is the interface file

 Most of the binding decision in Objective-C can be made in run-time.

 Adds automatic garbage collection

 In October 2007, Apple Inc. releases Objective-C 2.0 for Mac OS 10.5
(Leopard)
CONTENTS :
1. Introduction
2. History
3. Why Objective C ?
4. ID
5. Dynamic Typing
6. Messages
7. Polymorphism and Inheritance
8. Interfaces and Implementation
9. Objective C vs. C++
10.“Objective C”
CONCLUSION
“Although the differences can fade into shades of grey, Objective-C is different
from C++. C++ is traditionally associated with the Simula 67 school of object-
oriented programming where Objective-C has SmallTalk roots. In C++, the static
type of an object determines whether it can receive a message. In Objective-C
the dynamic type of an object determines whether it can receive a message. The
Simula 67 format is more structured and allows problems to be detected earlier
when a program is compiled. The Smalltalk approach delays it's typing until
runtime and is touted as a more flexible alternative.”

“This flexibility extends the language into three separate areas: Dynamic Typing,
Dynamic Binding and Dynamic Loading.”
REFERENCES
http://www.wikipedia.org 
http://developer.apple.com
http://www.mactech.com
http://www.cs.indiana.edu
http://www.kmittv.com
Any Queries…?
Thank you…!

You might also like