Objective-CDrew ChengCS420
Overview
True superset of ANSI C
Object-Oriented methods from SmallTalk
There is no formal written standard for the language
Relies on outside libraries
Iterative/Imperative
Flexibility, most things are done at runtimeDynamic Typing
Dynamic Binding
Dynamic Linking
Message Passing
History
Created by Brad Cox and Tom Love at their company Stepstone
Both were introduced to SmallTalk while working at ITT
Cox was interested in the problems of true reusability in software design and programming
Modified C compiler and created a Object-Oriented extension of C called OOPC
Tom Love added more to OOPC from SmallTalk creating Objective-C
1986 – Stepstone releases Objective-C
1988 – Steve Jobs acquires Objective-C license for NeXT
NeXT releases their own Objective-C compiler and libraries used in NeXTstep Operating System and OpenStep API
1993 – GNU Objective-C runtime, currently in use, created by Kresten Thorup
1996 – Apple Inc. acquires NeXT and uses OpenStep in new Mac OS X
Apple combines Objective-C and NeXT’s Objective-C, creates Cocoa API, most significant environment
Uniqueness
Messaging/ForwardingDoes not call method, sends message
Target of message is resolved at runtime
Message passing has no type checking
Receiver not guaranteed to respond. No response either return null pointer or “forward” to an object that will respond
Initial interpretation of message in Objc-C 3x longer than C++ virtual method call. Messages are cached and subsequent calls 50% faster than C++ method call.
Categories/Protocols
PrimitivesInt, float, double, char
Unsigned, signed, short, long, long long
id – Generic object typeCan be used to store any object
Essential to Objective-C’s dynamic binding
If/Else Statements, For/While/Do Loops
Combine features by nesting, “and/or” conditionals
Abstraction – variables, functions, classes
Functions
Variable Passing
Default method is pass-by-value for primitive data types
Objects use pass-by-reference
Impossible to use pass-by-value for Objects
Does not pass by result, value-result, name, or need
Type Checking
Dynamic type checking
Considered weak typed language
Language supports coercionWhen adding float and int, one is changed
Does not support type inference
Object-Oriented
Does not support multiple inheritance
Class must inherit from Object/NSObject class
Variable inheritance is dynamic
Method inheritance is dynamic
The super-method invocation uses method from class that super is called in (dynamic)
No operation and method overloading
Conclusion
Very easy to learn
Simple way of handling classes and objects
Dynamism allows flexibility in code
Errors may are not found until runtime
Not a very used language outside Apple