SlideShare a Scribd company logo
1 of 54
iOS Application Development
Object Oriented Programming with
Objective-C (Part 1)
These are confidential sessions - please refrain from streaming, blogging, or taking pictures
Session 3
Vu Tran Lam
IAD-2013
• Object-oriented programming (OOP) concept
• Classes and objects
• Properties
• Methods
Today’s Topics
• Data and operation
• Interface and Implementation
OOP Concept
• Programming languages have traditionally divided the world into two parts
—data and operations on data.
• Data is static and immutable, except as the operations may change it.
• The procedures and functions that operate on data have no lasting state of their
own; they’re useful only in their ability to affect data.
• With a procedural programming language like C, that’s about all there is to
it. The language may offer various kinds of support for organizing data and
functions, but it won’t divide the world any differently. Functions and data
structures are the basic elements of design.
• Object-oriented programming doesn’t so much dispute this view of the
world as restructure it at a higher level. It groups operations and data into
modular units called objects and lets you combine objects into structured
networks to form a complete program. In an object-oriented programming
language, objects and object interactions are the basic elements of
design.
Data and operation
• To invent programs, you need to be able to capture abstractions
and express them in the program design.
• All programming languages provide devices that help express
abstractions. In essence, these devices are ways of grouping
implementation details, hiding them, and giving them, at least to
some extent, a common interface—much as a mechanical object
separates its interface from its implementation,
Interface and Implementation
• As in many other object-oriented programming language,
Objective-C classes provide the blueprint for creating objects. First,
you define a reusable set of properties and behaviors inside of a
class. Then, you instantiate objects from that class to interact with
those properties and behaviors.
• Objective-C is similar to C++ in that it abstracts a class’s interface
from its implementation. An interface declares the public properties
and methods of a class, and the corresponding implementation
defines the code that actually makes these properties and methods
work. This is the same separation of concerns that we saw with
functions.
Classed and Objects
Classed and Objects
Classed and Objects
Classed and Objects
Data
method
method
method
method
Data
method
method
method
method
Data
method
method
method
method
Data
method
method
method
method
Data
method
method
method
method
create
Objects
Class
• To create a new class, navigate to File > New > File > OS X >
Cocoa > Objective - C class and then name class with “Car”. After
these steps, Xcode a class with two files, interface file named Car.h
(also called a “header”) and whose implementation resides in Car.m.
Creating Classes
• Car.h contains some template code, but let’s go ahead and change it to the
following. This declares a property called model and a method called drive.
• An interface is created with the @interface directive, after which come the
class and the superclass name, separated by a colon. Protected variables
can be defined inside of the curly braces, but most developers treat
instance variables as implementation details and prefer to store them in
the .m file instead of the interface.
• The @property directive declares a public property, and the (copy) attribute
defines its memory management behavior. In this case, the value assigned
to model will be stored as a copy instead of a direct pointer. The Properties
module discusses this in more detail. Next come the property’s data type
and name, just like a normal variable declaration.
• The -(void)drive line declares a method called drive that takes no
parameters, and the (void) portion defines its return type.
Interfaces
#import <Foundation/Foundation.h>
!
@interface Car : NSObject
{
// Protected instance variables (not recommended)
}
!
@property (copy) NSString *model;
!
- (void)drive;
!
@end
Interfaces
• The first thing any class implementation needs to do is import its
corresponding interface. The @implementation directive is similar to
@interface, except you don’t need to include the super class. Private
instance variables can be stored between curly braces after the class
name.
• The drive implementation has the same signature as the interface, but
it’s followed by whatever code should be executed when the method is
called. Note how we accessed the value via self.model instead of the
_model instance variable. This is a best practice step because it utilizes
the property’s accessor methods. Typically, the only place you’ll need to
directly access instance variables is in init methods and the dealloc
method.
• The self keyword refers to the instance calling the method (like this in C
++ and Java).
Implementations
• The first thing any class implementation needs to do is import its
corresponding interface. The @implementation directive is similar to
@interface, except you don’t need to include the super class. Private
instance variables can be stored between curly braces after the class
name.
• The drive implementation has the same signature as the interface, but
it’s followed by whatever code should be executed when the method is
called. Note how we accessed the value via self.model instead of the
_model instance variable. This is a best practice step because it utilizes
the property’s accessor methods. Typically, the only place you’ll need to
directly access instance variables is in init methods and the dealloc
method.
• The self keyword refers to the instance calling the method (like this in C
++ and Java).
Implementations
#import "Car.h"
!
@implementation Car
{
// Protected instance variables (not recommended)
double odometer;
}
!
@synthesize model = _model; // automatically create _mode in Xcode 4.4+
!
- (void)drive
{
NSLog(@"Drive a %@ Vrooooom!", self.model);
}
!
@end
Implementations
• Any files that need access to a class must import its header file
(Car.h)—they should never, ever try to access the implementation
file directly. That would defeat the goal of separating the public API
from its underlying implementation.
• After the interface has been imported with the #import directive,
you can instantiate objects with the alloc/init pattern shown above.
As you can see, instantiation is a two-step process: first you must
allocate some memory for the object by calling the alloc method,
then you need to initialize it so it’s ready to use. You should never
use an uninitialized object.
• To call a method on an Objective-C object, you place the instance
and the method in square brackets, separated by a space:
[toyota setModel:@"Toyota Corolla"]
Instantiation and Usage
#import <Foundation/Foundation.h>
#import "Car.h"
!
int main(int argc, const char * argv[])
{
@autoreleasepool
{
// Create an instance of Car object
Car *toyota = [[Car alloc]init];
// Use get/set model method to update car's model
[toyota setModel:@"Toyota Corolla"];
NSLog(@"Created a %@", [toyota model]);
// Use property to update car's model
toyota.model = @"Toyota Camry";
NSLog(@"Changed the car to %@", toyota.model);
// Call method drive of toyota object
[toyota drive];
}
return 0;
}
Instantiation and Usage
• The above snippets define instance-level properties and methods,
but it’s also possible to define class-level ones. These are
commonly called “static” methods/properties in other programming
languages (not to be confused with the static keyword).
• Class method declarations look just like instance methods, except
they are prefixed with a plus sign instead of a minus sign. For
example, let’s add the following class-level method to Car.h
// Decalare class method
+ (void) setDefaultModel:(NSString *)model;
Class Methods and Variables
• Similarly, a class method implementation is also preceded by a plus
sign. While there is technically no such thing as a class-level
variable in Objective-C, you can emulate one by declaring a static
variable before defining the implementation:
#import "Car.h"
!
static NSString *_defaultModel;
!
@implementation Car
!
...
!
+ (void)setDefaultModel:(NSString *)model
{
_defaultModel = [model copy];
}
!
@end
Class Methods and Variables
• Class methods use the same square-bracket syntax as instance
methods, but they must be called directly on the class, as shown
below. They cannot be called on an instance of that class
([toyota setDefaultModel:@"Model T"] will throw an error).
// Call class method
[Car setDefaultModel:@"Nissan Versa"];
Class Methods and Variables
• There are no constructor methods in Objective-C. Instead, an
object is initialized by calling the init method immediately after it’s
allocated. This is why instantiation is always a two-step process:
allocate, then initialize. There is also a class-level initialization
method that will be discussed in a moment.
• init is the default initialization method, but you can also define your
own versions to accept configuration parameters. There’s nothing
special about custom initialization methods—they’re just normal
instance methods, except the method name should always begin
with init. An exemplary “constructor” method is shown below.
// Declare the contructor
- (id)initWithModel:(NSString *)model;
“Constructor” Methods
• To implement this method, you should follow the canonical
initialization pattern shown in initWithModel: below. The super
keyword refers to the parent class, and again, the self keyword
refers to the instance calling the method. Go ahead and add the
following methods to Car.m.
- (id)initWithModel:(NSString *)aModel
{
self = [super init];
if (self)
{
_model = [aModel copy];
odometer = 0;
}
return self;
}
“Constructor” Methods
• In main.m class you can create an instance of Car by using
initWitModel contructor:
// Car.m
Car *toyota = [[Car alloc]initWithModel:@"Toyota Corolla"];
“Constructor” Methods
• We’ll be working with a class called Car whose interface resides in
a file named Car.h (also called a “header”) and whose
implementation resides in Car.m. These are the standard file
extensions for Objective-C classes. The class’s header file is what
other classes use when they need to interact with it, and its
implementation file is used only by the compiler.
• Xcode provides a convenient template for creating new classes. To
create our Car class, navigate to File > New > File… or use the
Cmd+N shortcut. For the template, choose Objective-C class
under the iOS > Cocoa Touch category. After that, you’ll be
presented with some configuration options:
Dynamic Typing
• An object’s properties let other objects inspect or change its state.
But, in a well-designed object-oriented program, it’s not possible to
directly access the internal state of an object. Instead, accessor
methods (getters and setters) are used as an abstraction for
interacting with the object’s underlying data.
• The goal of the @property directive is to make it easy to create and
configure properties by automatically generating these accessor
methods. It allows you to specify the behavior of a public property
on a semantic level, and it takes care of the implementation details
for you.
Properties
• First, let’s take at what’s going on under the hood when we use the
@property directive. Consider the following interface for a simple Car
class and it’s corresponding implementation.
// Car.h
@property BOOL running;
!
// Car.m
@synthesize running = _running;
• The compiler generates a getter and a setter for the running property.
The default naming convention is to use the property itself as the getter,
prefix it with set for the setter, and prefix it with an underscore for the
instance variable, like so:
- (BOOL)running
{
return _running;
}
!
- (void)setRunning:(BOOL)running
{
_running = running;
}
The @property Directive
• If you don’t like @property’s default naming conventions, you can
change the getter/setter method names with the getter= and
setter= attributes. A common use case for this is Boolean
properties, whose getters are conventionally prefixed with is. Try
changing the property declaration in Car.h to the following:
// Car.h
@property (getter = isRunning) BOOL running;
!
• The generated accessors are now called isRunning and
setRunning. Note that the public property is still called running, and
this is what you should use for dot-notation:
// Car.m
Car *honda = [[Car alloc]init];
honda.running = YES; // [honda setRunning:YES]
NSLog(@"%d", honda.running); // [honda isRunning]
NSLog(@"%d", [honda running]); // Error: method no longer exists
The getter= and setter= Attributes
• The readonly attribute is an easy way to make a property read-only.
It omits the setter method and prevents assignment via dot-
notation, but the getter is unaffected. As an example, let’s change
our Car interface to the following. Notice how you can specify
multiple attributes by separating them with a comma.
// Car.h
@property (getter = isRunning, readonly) BOOL running;
!
- (void)startEngine;
- (void)stopEngine;
The readonly Attribute
• Instead of letting other objects change the running property, we’ll
set it internally via the startEngine and stopEngine methods. The
corresponding implementation can be found below.
// Car.m
- (void)startEngine
{
_running = YES;
NSLog(@"Car is running!");
}
!
- (void)stopEngine
{
_running = NO;
NSLog(@"Car is stopped");
}
The readonly Attribute
• Remember that @property also generates an instance variable for
us, which is why we can access _running without declaring it
anywhere (we can’t use self.running here because the property is
read-only). Let’s test this new Car class by adding the following
snippet to main.m.
Car *honda = [[Car alloc]init];
[honda startEngine];
NSLog(@"%d", honda.running);
honda.running = NO; // Error: read-only property
The readonly Attribute
• Atomicity has to do with how properties behave in a threaded
environment. When you have more than one thread, it’s possible for
the setter and the getter to be called at the same time. This means
that the getter/setter can be interrupted by another operation,
possibly resulting in corrupted data.
// Car.h
@property (nonatomic) NSString *model;
The nonatomic Attribute
• In any OOP language, objects reside in the computer’s memory,
and—especially on mobile devices—this is a scarce resource. The
goal of a memory management system is to make sure that
programs don’t take up any more space than they need to by
creating and destroying objects in an efficient manner.
• Many languages accomplish this through garbage collection, but
Objective-C uses a more efficient alternative called object
ownership. When you start interacting with an object, you’re said to
own that object, which means that it’s guaranteed to exist as long
as you’re using it. When you’re done with it, you relinquish
ownership, and—if the object has no other owners—the operating
system destroys the object and frees up the underlying memory.
Memory Management
• With the advent of Automatic Reference Counting, the compiler
manages all of your object ownership automatically.
Memory Management
• The implementation is shown below. It uses the default accessors
generated by @property. It also overrides NSObject’s description
method, which returns the string representation of the object.
// Person.h
!
#import <Foundation/Foundation.h>
!
@interface Person : NSObject
!
@property (nonatomic) NSString *name;
!
@end
The strong Attribute
• The implementation is shown below. It uses the default accessors
generated by @property. It also overrides NSObject’s description
method, which returns the string representation of the object.
// Car.h
!
#import <Foundation/Foundation.h>
#import "Person.h"
!
@interface Car : NSObject
!
@property (nonatomic) NSString *model;
@property (nonatomic, strong) Person *driver;
!
@end
The strong Attribute
• Then, consider the following iteration of main.m:
!
// main.m
!
Person *john = [[Person alloc]init];
john.name = @"John";
Car *honda = [[Car alloc]init];
honda.model = @"Honda Civic";
honda.driver = john;
NSLog(@"%@ drives a %@", honda.driver, honda.model);
The strong Attribute
• Most of the time, the strong attribute is intuitively what you want for object
properties. However, strong references pose a problem if, for example,
we need a reference from driver back to the Car object he’s driving. First,
let’s add a car property to Person.h:
// Person.h
!
#import <Foundation/Foundation.h>
!
@class Car;
!
@interface Person : NSObject
!
@property (nonatomic) NSString *name;
@property (nonatomic, strong) Car *car;
!
@end
• The @class Car line is a forward declaration of the Car class. It’s like
telling the compiler, “Trust me, the Car class exists, so don’t try to find it
right now.” We have to do this instead of our usual #import statement
because Car also imports Person.h, and we would have an endless loop
of imports.
The weak Attribute
• Next, add the following line to main.m right after the honda.driver
assignment:
// main.m
!
honda.driver = john;
john.car = honda; // Add this line
• We now have an owning relationship from honda to john and
another owning relationship from john to honda. This means that
both objects will always be owned by another object, so the
memory management system won’t be able to destroy them even if
they’re no longer needed.
The weak Attribute
!
!
!
!
• This is called a retain cycle, which is a form of memory leak, and
memory leaks are bad. Fortunately, it’s very easy to fix this problem
—just tell one of the properties to maintain a weak reference to the
other object. In Person.h, change the car declaration to the
following:
// Person.h
@property (nonatomic, weak) Person *driver;
The weak Attribute
A retain cycle between the Car and Person classes
• The weak attribute creates a non-owning relationship to car. This
allows john to have a reference to honda while avoiding a retain
cycle. But, this also means that there is a possibility that honda will
be destroyed while john still has a reference to it. Should this
happen, the weak attribute will conveniently set car to nil in order to
avoid a dangling pointer.
The weak Attribute
A weak reference from the Person class to Car
• A common use case for the weak attribute is parent-child data
structures. By convention, the parent object should maintain a
strong reference with it’s children, and the children should store a
weak reference back to the parent. Weak references are also an
inherent part of the delegate design pattern.
• The point to take away is that two objects should never have strong
references to each other. The weak attribute makes it possible to
maintain a cyclical relationship without creating a retain cycle.
The weak Attribute
• The copy attribute is an alternative to strong. Instead of taking
ownership of the existing object, it creates a copy of whatever you
assign to the property, then takes ownership of that. Only objects
that conform to the NSCopying protocol can use this attribute.
• Properties that represent values (opposed to connections or
relationships) are good candidates for copying. For example,
developers usually copy NSString properties instead of strongly
reference them:
// Car.h
@property (nonatomic, copy) NSString *model;
The copy Attribute
• Now, Car will store a brand new instance of whatever value we
assign to model. If you’re working with mutable values, this has the
added perk of freezing the object at whatever value it had when it
was assigned. This is demonstrated below:
// main.m
!
Car *honda = [[Car alloc]init];
NSMutableString *model = [NSMutableString stringWithFormat:@"Honda Civic"];
honda.model = model;
NSLog(@"%@", honda.model);
[model setString:@"Nissa Versa"];
NSLog(@"%@", honda.model); // Still Honda Civic
• NSMutableString is a subclass of NSString that can be edited in-
place. If the model property didn’t create a copy of the original
instance, we would be able to see the altered string (Nissan Versa)
in the second NSLog() output.
The copy Attribute
Attributes Summary
Attribute Description
getter= Use a custom name for the getter method.
setter= Use a custom name for the setter method.
readonly Don’t synthesize a setter method.
nonatomic Don’t guarantee the integrity of accessors in a multi-threaded
environment. This is more efficient than the default atomic
behavior.strong Create an owning relationship between the property and the
assigned value. This is the default for object properties.
weak Create a non-owning relationship between the property and
the assigned value. Use this to prevent retain cycles.
copy Create a copy of the assigned value instead of referencing the
existing instance.
• Methods represent the actions that an object knows how to
perform. They’re the logical counterpart to properties, which
represent an object’s data. You can think of methods as functions
that are attached to an object; however, they have a very different
syntax.
Methods
• Objective-C methods are designed to remove all ambiguities from
an API. As a result, method names are horribly verbose, but
undeniably descriptive.
// Car.h
!
// Accessors
- (BOOL)isRunning;
- (void)setRunning:(BOOL)running;
- (NSString *)model;
- (void)setModel:(NSString *)model;
!
// Action methods
- (void)startEngine;
- (void)turnToAngle:(double)theAngle;
!
// Constructor methods
- (id)initWithModel:(NSString *)aModel;
- (id)initWithModel:(NSString *)aModel mileage:(double)theMileage;
!
// Factory methods
+ (Car *)car;
+ (Car *)carWithModel:(NSString *)aModel;
Naming Conventions
• Nesting method calls is a common pattern in Objective-C
programs. It’s a natural way to pass the result of one call to another.
Conceptually, it’s the exact same as chaining methods, but the
square-bracket syntax makes them look a little bit different:
Car *car = [[Car alloc]initWithModel:@"Honda Civic" mileage:400];
• First, the [Car alloc] method is invoked, then the init method is
called on its return value.
Nested Calling Methods
• There are no protected or private access modifiers for Objective-C
methods—they are all public. However, Objective-C does provide
alternative organizational paradigms that let you emulate these
features.
Protected and Private Methods
• Selectors are Objective-C’s internal representation of a method
name. They let you treat a method as an independent entity,
enabling you to separate an action from the object that needs to
perform it. This is the basis of the Target-Action design pattern, and
it is an integral part of Objective-C’s dynamic typing system.
• There are two ways to get the selector for a method name. The
@selector() directive lets you convert a source-code method name
to a selector, and the NSSelectorFromString() function lets you
convert a string to a selector (the latter is not as efficient). Both of
these return a special data type for selectors called SEL. You can
use SEL the exact same way as BOOL, int, or any other data type.
Selectors
// main.m
!
Car *porsche = [[Car alloc] init];
porsche.model = @"Porsche 911 Carrera";
!
SEL stepOne = NSSelectorFromString(@"startEngine");
SEL stepTwo = @selector(driveForDistance:);
!
// This is the same as:
// [porsche startEngine];
[porsche performSelector:stepOne];
!
// This is the same as:
// [porsche driveForDistance:[NSNumber numberWithDouble:5.7]];
[porsche performSelector:stepTwo withObject:[NSNumber numberWithDouble:5.7]];
Selectors
Documentation
Object-Oriented Programming with Objective-C
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/OOP_ObjC/Introduction/
Introduction.html
Programming with Objective-C
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/
Introduction/Introduction.html
many thanks
to
lamvt@fpt.com.vn
please
say
Stanford University
https://developer.apple.com
Developer Center
http://www.stanford.edu/class/cs193p
xin
chào
Next: Object Oriented Programming with
Objective-C (Part 2)

More Related Content

What's hot

Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaKnoldus Inc.
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course yoavrubin
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7sumitbardhan
 
Algebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain ModelsAlgebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain ModelsDebasish Ghosh
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsDebasish Ghosh
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence APIIlio Catallo
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NETBlackRabbitCoder
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongVu Huy
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3Duong Thanh
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++Dmitri Nesteruk
 
10. symbols | ES6 | JavaScript | TypeScript
10. symbols | ES6 | JavaScript | TypeScript10. symbols | ES6 | JavaScript | TypeScript
10. symbols | ES6 | JavaScript | TypeScriptpcnmtutorials
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Gostrikr .
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersRichard Thomson
 

What's hot (20)

Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
 
Javascript
JavascriptJavascript
Javascript
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Algebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain ModelsAlgebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain Models
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
106da session5 c++
106da session5 c++106da session5 c++
106da session5 c++
 
Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
CSharp for Unity Day 3
CSharp for Unity Day 3CSharp for Unity Day 3
CSharp for Unity Day 3
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
10. symbols | ES6 | JavaScript | TypeScript
10. symbols | ES6 | JavaScript | TypeScript10. symbols | ES6 | JavaScript | TypeScript
10. symbols | ES6 | JavaScript | TypeScript
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmers
 
OOP - Templates
OOP - TemplatesOOP - Templates
OOP - Templates
 

Viewers also liked

Session 1 - Introduction to iOS 7 and SDK
Session 1 -  Introduction to iOS 7 and SDKSession 1 -  Introduction to iOS 7 and SDK
Session 1 - Introduction to iOS 7 and SDKVu Tran Lam
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsPetr Dvorak
 
Фундаментальные основы разработки под iOS. Павел Тайкало
Фундаментальные основы разработки под iOS. Павел ТайкалоФундаментальные основы разработки под iOS. Павел Тайкало
Фундаментальные основы разработки под iOS. Павел ТайкалоStanfy
 
Session 16 - Designing universal interface which used for iPad and iPhone
Session 16  -  Designing universal interface which used for iPad and iPhoneSession 16  -  Designing universal interface which used for iPad and iPhone
Session 16 - Designing universal interface which used for iPad and iPhoneVu Tran Lam
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentVu Tran Lam
 
Session 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barSession 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barVu Tran Lam
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
 Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья... Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...Yandex
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
Architecture iOS et Android
Architecture iOS et AndroidArchitecture iOS et Android
Architecture iOS et AndroidHadina RIMTIC
 

Viewers also liked (12)

Session 1 - Introduction to iOS 7 and SDK
Session 1 -  Introduction to iOS 7 and SDKSession 1 -  Introduction to iOS 7 and SDK
Session 1 - Introduction to iOS 7 and SDK
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
Фундаментальные основы разработки под iOS. Павел Тайкало
Фундаментальные основы разработки под iOS. Павел ТайкалоФундаментальные основы разработки под iOS. Павел Тайкало
Фундаментальные основы разработки под iOS. Павел Тайкало
 
Session 16 - Designing universal interface which used for iPad and iPhone
Session 16  -  Designing universal interface which used for iPad and iPhoneSession 16  -  Designing universal interface which used for iPad and iPhone
Session 16 - Designing universal interface which used for iPad and iPhone
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone Development
 
Session 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barSession 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab bar
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
20111002 csseminar kotlin
20111002 csseminar kotlin20111002 csseminar kotlin
20111002 csseminar kotlin
 
Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
 Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья... Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
Меньше кода — больше сути. Внедрение Kotlin для разработки под Android. Илья...
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Architecture iOS et Android
Architecture iOS et AndroidArchitecture iOS et Android
Architecture iOS et Android
 

Similar to Session 3 - Object oriented programming with Objective-C (part 1)

Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Manykenatmxm
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Hemlathadhevi Annadhurai
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
A350103
A350103A350103
A350103aijbm
 
2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation FundamentalsMichael Heron
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Salesforce Developers
 
OOP in C# Classes and Objects.
OOP in C# Classes and Objects.OOP in C# Classes and Objects.
OOP in C# Classes and Objects.Abid Kohistani
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Sachintha Gunasena
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction paramisoft
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript Rohit Bishnoi
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 

Similar to Session 3 - Object oriented programming with Objective-C (part 1) (20)

Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
ProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPSProgrammingPrimerAndOOPS
ProgrammingPrimerAndOOPS
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
A350103
A350103A350103
A350103
 
2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals2CPP03 - Object Orientation Fundamentals
2CPP03 - Object Orientation Fundamentals
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 
OOP in C# Classes and Objects.
OOP in C# Classes and Objects.OOP in C# Classes and Objects.
OOP in C# Classes and Objects.
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1
 
MDE in Practice
MDE in PracticeMDE in Practice
MDE in Practice
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Angular2 with TypeScript
Angular2 with TypeScript Angular2 with TypeScript
Angular2 with TypeScript
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Aem best practices
Aem best practicesAem best practices
Aem best practices
 

More from Vu Tran Lam

Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Vu Tran Lam
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search barVu Tran Lam
 
Session 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 applicationSession 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 applicationVu Tran Lam
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationVu Tran Lam
 
Session 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architectureSession 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architectureVu Tran Lam
 
Session 5 - Foundation framework
Session 5 - Foundation frameworkSession 5 - Foundation framework
Session 5 - Foundation frameworkVu Tran Lam
 
Session 4 - Object oriented programming with Objective-C (part 2)
Session 4  - Object oriented programming with Objective-C (part 2)Session 4  - Object oriented programming with Objective-C (part 2)
Session 4 - Object oriented programming with Objective-C (part 2)Vu Tran Lam
 
iOS 7 Application Development Course
iOS 7 Application Development CourseiOS 7 Application Development Course
iOS 7 Application Development CourseVu Tran Lam
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web ViewVu Tran Lam
 
Succeed in Mobile career
Succeed in Mobile careerSucceed in Mobile career
Succeed in Mobile careerVu Tran Lam
 
Android Application Development Course
Android Application Development Course Android Application Development Course
Android Application Development Course Vu Tran Lam
 
Your Second iPhone App - Code Listings
Your Second iPhone App - Code ListingsYour Second iPhone App - Code Listings
Your Second iPhone App - Code ListingsVu Tran Lam
 
Building a Completed iPhone App
Building a Completed iPhone AppBuilding a Completed iPhone App
Building a Completed iPhone AppVu Tran Lam
 
Introduction to iPhone Programming
Introduction to iPhone Programming Introduction to iPhone Programming
Introduction to iPhone Programming Vu Tran Lam
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignVu Tran Lam
 
HTML5 Web Standards
HTML5 Web StandardsHTML5 Web Standards
HTML5 Web StandardsVu Tran Lam
 
3D & Animation Effects Using CSS3 & jQuery
3D & Animation Effects Using CSS3 & jQuery3D & Animation Effects Using CSS3 & jQuery
3D & Animation Effects Using CSS3 & jQueryVu Tran Lam
 

More from Vu Tran Lam (17)

Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search bar
 
Session 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 applicationSession 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 application
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 application
 
Session 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architectureSession 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architecture
 
Session 5 - Foundation framework
Session 5 - Foundation frameworkSession 5 - Foundation framework
Session 5 - Foundation framework
 
Session 4 - Object oriented programming with Objective-C (part 2)
Session 4  - Object oriented programming with Objective-C (part 2)Session 4  - Object oriented programming with Objective-C (part 2)
Session 4 - Object oriented programming with Objective-C (part 2)
 
iOS 7 Application Development Course
iOS 7 Application Development CourseiOS 7 Application Development Course
iOS 7 Application Development Course
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
 
Succeed in Mobile career
Succeed in Mobile careerSucceed in Mobile career
Succeed in Mobile career
 
Android Application Development Course
Android Application Development Course Android Application Development Course
Android Application Development Course
 
Your Second iPhone App - Code Listings
Your Second iPhone App - Code ListingsYour Second iPhone App - Code Listings
Your Second iPhone App - Code Listings
 
Building a Completed iPhone App
Building a Completed iPhone AppBuilding a Completed iPhone App
Building a Completed iPhone App
 
Introduction to iPhone Programming
Introduction to iPhone Programming Introduction to iPhone Programming
Introduction to iPhone Programming
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
HTML5 Web Standards
HTML5 Web StandardsHTML5 Web Standards
HTML5 Web Standards
 
3D & Animation Effects Using CSS3 & jQuery
3D & Animation Effects Using CSS3 & jQuery3D & Animation Effects Using CSS3 & jQuery
3D & Animation Effects Using CSS3 & jQuery
 

Recently uploaded

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Recently uploaded (20)

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Session 3 - Object oriented programming with Objective-C (part 1)

  • 2. Object Oriented Programming with Objective-C (Part 1) These are confidential sessions - please refrain from streaming, blogging, or taking pictures Session 3 Vu Tran Lam IAD-2013
  • 3. • Object-oriented programming (OOP) concept • Classes and objects • Properties • Methods Today’s Topics
  • 4. • Data and operation • Interface and Implementation OOP Concept
  • 5. • Programming languages have traditionally divided the world into two parts —data and operations on data. • Data is static and immutable, except as the operations may change it. • The procedures and functions that operate on data have no lasting state of their own; they’re useful only in their ability to affect data. • With a procedural programming language like C, that’s about all there is to it. The language may offer various kinds of support for organizing data and functions, but it won’t divide the world any differently. Functions and data structures are the basic elements of design. • Object-oriented programming doesn’t so much dispute this view of the world as restructure it at a higher level. It groups operations and data into modular units called objects and lets you combine objects into structured networks to form a complete program. In an object-oriented programming language, objects and object interactions are the basic elements of design. Data and operation
  • 6. • To invent programs, you need to be able to capture abstractions and express them in the program design. • All programming languages provide devices that help express abstractions. In essence, these devices are ways of grouping implementation details, hiding them, and giving them, at least to some extent, a common interface—much as a mechanical object separates its interface from its implementation, Interface and Implementation
  • 7. • As in many other object-oriented programming language, Objective-C classes provide the blueprint for creating objects. First, you define a reusable set of properties and behaviors inside of a class. Then, you instantiate objects from that class to interact with those properties and behaviors. • Objective-C is similar to C++ in that it abstracts a class’s interface from its implementation. An interface declares the public properties and methods of a class, and the corresponding implementation defines the code that actually makes these properties and methods work. This is the same separation of concerns that we saw with functions. Classed and Objects
  • 11. • To create a new class, navigate to File > New > File > OS X > Cocoa > Objective - C class and then name class with “Car”. After these steps, Xcode a class with two files, interface file named Car.h (also called a “header”) and whose implementation resides in Car.m. Creating Classes
  • 12. • Car.h contains some template code, but let’s go ahead and change it to the following. This declares a property called model and a method called drive. • An interface is created with the @interface directive, after which come the class and the superclass name, separated by a colon. Protected variables can be defined inside of the curly braces, but most developers treat instance variables as implementation details and prefer to store them in the .m file instead of the interface. • The @property directive declares a public property, and the (copy) attribute defines its memory management behavior. In this case, the value assigned to model will be stored as a copy instead of a direct pointer. The Properties module discusses this in more detail. Next come the property’s data type and name, just like a normal variable declaration. • The -(void)drive line declares a method called drive that takes no parameters, and the (void) portion defines its return type. Interfaces
  • 13. #import <Foundation/Foundation.h> ! @interface Car : NSObject { // Protected instance variables (not recommended) } ! @property (copy) NSString *model; ! - (void)drive; ! @end Interfaces
  • 14. • The first thing any class implementation needs to do is import its corresponding interface. The @implementation directive is similar to @interface, except you don’t need to include the super class. Private instance variables can be stored between curly braces after the class name. • The drive implementation has the same signature as the interface, but it’s followed by whatever code should be executed when the method is called. Note how we accessed the value via self.model instead of the _model instance variable. This is a best practice step because it utilizes the property’s accessor methods. Typically, the only place you’ll need to directly access instance variables is in init methods and the dealloc method. • The self keyword refers to the instance calling the method (like this in C ++ and Java). Implementations
  • 15. • The first thing any class implementation needs to do is import its corresponding interface. The @implementation directive is similar to @interface, except you don’t need to include the super class. Private instance variables can be stored between curly braces after the class name. • The drive implementation has the same signature as the interface, but it’s followed by whatever code should be executed when the method is called. Note how we accessed the value via self.model instead of the _model instance variable. This is a best practice step because it utilizes the property’s accessor methods. Typically, the only place you’ll need to directly access instance variables is in init methods and the dealloc method. • The self keyword refers to the instance calling the method (like this in C ++ and Java). Implementations
  • 16. #import "Car.h" ! @implementation Car { // Protected instance variables (not recommended) double odometer; } ! @synthesize model = _model; // automatically create _mode in Xcode 4.4+ ! - (void)drive { NSLog(@"Drive a %@ Vrooooom!", self.model); } ! @end Implementations
  • 17. • Any files that need access to a class must import its header file (Car.h)—they should never, ever try to access the implementation file directly. That would defeat the goal of separating the public API from its underlying implementation. • After the interface has been imported with the #import directive, you can instantiate objects with the alloc/init pattern shown above. As you can see, instantiation is a two-step process: first you must allocate some memory for the object by calling the alloc method, then you need to initialize it so it’s ready to use. You should never use an uninitialized object. • To call a method on an Objective-C object, you place the instance and the method in square brackets, separated by a space: [toyota setModel:@"Toyota Corolla"] Instantiation and Usage
  • 18. #import <Foundation/Foundation.h> #import "Car.h" ! int main(int argc, const char * argv[]) { @autoreleasepool { // Create an instance of Car object Car *toyota = [[Car alloc]init]; // Use get/set model method to update car's model [toyota setModel:@"Toyota Corolla"]; NSLog(@"Created a %@", [toyota model]); // Use property to update car's model toyota.model = @"Toyota Camry"; NSLog(@"Changed the car to %@", toyota.model); // Call method drive of toyota object [toyota drive]; } return 0; } Instantiation and Usage
  • 19. • The above snippets define instance-level properties and methods, but it’s also possible to define class-level ones. These are commonly called “static” methods/properties in other programming languages (not to be confused with the static keyword). • Class method declarations look just like instance methods, except they are prefixed with a plus sign instead of a minus sign. For example, let’s add the following class-level method to Car.h // Decalare class method + (void) setDefaultModel:(NSString *)model; Class Methods and Variables
  • 20. • Similarly, a class method implementation is also preceded by a plus sign. While there is technically no such thing as a class-level variable in Objective-C, you can emulate one by declaring a static variable before defining the implementation: #import "Car.h" ! static NSString *_defaultModel; ! @implementation Car ! ... ! + (void)setDefaultModel:(NSString *)model { _defaultModel = [model copy]; } ! @end Class Methods and Variables
  • 21. • Class methods use the same square-bracket syntax as instance methods, but they must be called directly on the class, as shown below. They cannot be called on an instance of that class ([toyota setDefaultModel:@"Model T"] will throw an error). // Call class method [Car setDefaultModel:@"Nissan Versa"]; Class Methods and Variables
  • 22. • There are no constructor methods in Objective-C. Instead, an object is initialized by calling the init method immediately after it’s allocated. This is why instantiation is always a two-step process: allocate, then initialize. There is also a class-level initialization method that will be discussed in a moment. • init is the default initialization method, but you can also define your own versions to accept configuration parameters. There’s nothing special about custom initialization methods—they’re just normal instance methods, except the method name should always begin with init. An exemplary “constructor” method is shown below. // Declare the contructor - (id)initWithModel:(NSString *)model; “Constructor” Methods
  • 23. • To implement this method, you should follow the canonical initialization pattern shown in initWithModel: below. The super keyword refers to the parent class, and again, the self keyword refers to the instance calling the method. Go ahead and add the following methods to Car.m. - (id)initWithModel:(NSString *)aModel { self = [super init]; if (self) { _model = [aModel copy]; odometer = 0; } return self; } “Constructor” Methods
  • 24. • In main.m class you can create an instance of Car by using initWitModel contructor: // Car.m Car *toyota = [[Car alloc]initWithModel:@"Toyota Corolla"]; “Constructor” Methods
  • 25. • We’ll be working with a class called Car whose interface resides in a file named Car.h (also called a “header”) and whose implementation resides in Car.m. These are the standard file extensions for Objective-C classes. The class’s header file is what other classes use when they need to interact with it, and its implementation file is used only by the compiler. • Xcode provides a convenient template for creating new classes. To create our Car class, navigate to File > New > File… or use the Cmd+N shortcut. For the template, choose Objective-C class under the iOS > Cocoa Touch category. After that, you’ll be presented with some configuration options: Dynamic Typing
  • 26. • An object’s properties let other objects inspect or change its state. But, in a well-designed object-oriented program, it’s not possible to directly access the internal state of an object. Instead, accessor methods (getters and setters) are used as an abstraction for interacting with the object’s underlying data. • The goal of the @property directive is to make it easy to create and configure properties by automatically generating these accessor methods. It allows you to specify the behavior of a public property on a semantic level, and it takes care of the implementation details for you. Properties
  • 27. • First, let’s take at what’s going on under the hood when we use the @property directive. Consider the following interface for a simple Car class and it’s corresponding implementation. // Car.h @property BOOL running; ! // Car.m @synthesize running = _running; • The compiler generates a getter and a setter for the running property. The default naming convention is to use the property itself as the getter, prefix it with set for the setter, and prefix it with an underscore for the instance variable, like so: - (BOOL)running { return _running; } ! - (void)setRunning:(BOOL)running { _running = running; } The @property Directive
  • 28. • If you don’t like @property’s default naming conventions, you can change the getter/setter method names with the getter= and setter= attributes. A common use case for this is Boolean properties, whose getters are conventionally prefixed with is. Try changing the property declaration in Car.h to the following: // Car.h @property (getter = isRunning) BOOL running; ! • The generated accessors are now called isRunning and setRunning. Note that the public property is still called running, and this is what you should use for dot-notation: // Car.m Car *honda = [[Car alloc]init]; honda.running = YES; // [honda setRunning:YES] NSLog(@"%d", honda.running); // [honda isRunning] NSLog(@"%d", [honda running]); // Error: method no longer exists The getter= and setter= Attributes
  • 29. • The readonly attribute is an easy way to make a property read-only. It omits the setter method and prevents assignment via dot- notation, but the getter is unaffected. As an example, let’s change our Car interface to the following. Notice how you can specify multiple attributes by separating them with a comma. // Car.h @property (getter = isRunning, readonly) BOOL running; ! - (void)startEngine; - (void)stopEngine; The readonly Attribute
  • 30. • Instead of letting other objects change the running property, we’ll set it internally via the startEngine and stopEngine methods. The corresponding implementation can be found below. // Car.m - (void)startEngine { _running = YES; NSLog(@"Car is running!"); } ! - (void)stopEngine { _running = NO; NSLog(@"Car is stopped"); } The readonly Attribute
  • 31. • Remember that @property also generates an instance variable for us, which is why we can access _running without declaring it anywhere (we can’t use self.running here because the property is read-only). Let’s test this new Car class by adding the following snippet to main.m. Car *honda = [[Car alloc]init]; [honda startEngine]; NSLog(@"%d", honda.running); honda.running = NO; // Error: read-only property The readonly Attribute
  • 32. • Atomicity has to do with how properties behave in a threaded environment. When you have more than one thread, it’s possible for the setter and the getter to be called at the same time. This means that the getter/setter can be interrupted by another operation, possibly resulting in corrupted data. // Car.h @property (nonatomic) NSString *model; The nonatomic Attribute
  • 33. • In any OOP language, objects reside in the computer’s memory, and—especially on mobile devices—this is a scarce resource. The goal of a memory management system is to make sure that programs don’t take up any more space than they need to by creating and destroying objects in an efficient manner. • Many languages accomplish this through garbage collection, but Objective-C uses a more efficient alternative called object ownership. When you start interacting with an object, you’re said to own that object, which means that it’s guaranteed to exist as long as you’re using it. When you’re done with it, you relinquish ownership, and—if the object has no other owners—the operating system destroys the object and frees up the underlying memory. Memory Management
  • 34. • With the advent of Automatic Reference Counting, the compiler manages all of your object ownership automatically. Memory Management
  • 35. • The implementation is shown below. It uses the default accessors generated by @property. It also overrides NSObject’s description method, which returns the string representation of the object. // Person.h ! #import <Foundation/Foundation.h> ! @interface Person : NSObject ! @property (nonatomic) NSString *name; ! @end The strong Attribute
  • 36. • The implementation is shown below. It uses the default accessors generated by @property. It also overrides NSObject’s description method, which returns the string representation of the object. // Car.h ! #import <Foundation/Foundation.h> #import "Person.h" ! @interface Car : NSObject ! @property (nonatomic) NSString *model; @property (nonatomic, strong) Person *driver; ! @end The strong Attribute
  • 37. • Then, consider the following iteration of main.m: ! // main.m ! Person *john = [[Person alloc]init]; john.name = @"John"; Car *honda = [[Car alloc]init]; honda.model = @"Honda Civic"; honda.driver = john; NSLog(@"%@ drives a %@", honda.driver, honda.model); The strong Attribute
  • 38. • Most of the time, the strong attribute is intuitively what you want for object properties. However, strong references pose a problem if, for example, we need a reference from driver back to the Car object he’s driving. First, let’s add a car property to Person.h: // Person.h ! #import <Foundation/Foundation.h> ! @class Car; ! @interface Person : NSObject ! @property (nonatomic) NSString *name; @property (nonatomic, strong) Car *car; ! @end • The @class Car line is a forward declaration of the Car class. It’s like telling the compiler, “Trust me, the Car class exists, so don’t try to find it right now.” We have to do this instead of our usual #import statement because Car also imports Person.h, and we would have an endless loop of imports. The weak Attribute
  • 39. • Next, add the following line to main.m right after the honda.driver assignment: // main.m ! honda.driver = john; john.car = honda; // Add this line • We now have an owning relationship from honda to john and another owning relationship from john to honda. This means that both objects will always be owned by another object, so the memory management system won’t be able to destroy them even if they’re no longer needed. The weak Attribute
  • 40. ! ! ! ! • This is called a retain cycle, which is a form of memory leak, and memory leaks are bad. Fortunately, it’s very easy to fix this problem —just tell one of the properties to maintain a weak reference to the other object. In Person.h, change the car declaration to the following: // Person.h @property (nonatomic, weak) Person *driver; The weak Attribute A retain cycle between the Car and Person classes
  • 41. • The weak attribute creates a non-owning relationship to car. This allows john to have a reference to honda while avoiding a retain cycle. But, this also means that there is a possibility that honda will be destroyed while john still has a reference to it. Should this happen, the weak attribute will conveniently set car to nil in order to avoid a dangling pointer. The weak Attribute A weak reference from the Person class to Car
  • 42. • A common use case for the weak attribute is parent-child data structures. By convention, the parent object should maintain a strong reference with it’s children, and the children should store a weak reference back to the parent. Weak references are also an inherent part of the delegate design pattern. • The point to take away is that two objects should never have strong references to each other. The weak attribute makes it possible to maintain a cyclical relationship without creating a retain cycle. The weak Attribute
  • 43. • The copy attribute is an alternative to strong. Instead of taking ownership of the existing object, it creates a copy of whatever you assign to the property, then takes ownership of that. Only objects that conform to the NSCopying protocol can use this attribute. • Properties that represent values (opposed to connections or relationships) are good candidates for copying. For example, developers usually copy NSString properties instead of strongly reference them: // Car.h @property (nonatomic, copy) NSString *model; The copy Attribute
  • 44. • Now, Car will store a brand new instance of whatever value we assign to model. If you’re working with mutable values, this has the added perk of freezing the object at whatever value it had when it was assigned. This is demonstrated below: // main.m ! Car *honda = [[Car alloc]init]; NSMutableString *model = [NSMutableString stringWithFormat:@"Honda Civic"]; honda.model = model; NSLog(@"%@", honda.model); [model setString:@"Nissa Versa"]; NSLog(@"%@", honda.model); // Still Honda Civic • NSMutableString is a subclass of NSString that can be edited in- place. If the model property didn’t create a copy of the original instance, we would be able to see the altered string (Nissan Versa) in the second NSLog() output. The copy Attribute
  • 45. Attributes Summary Attribute Description getter= Use a custom name for the getter method. setter= Use a custom name for the setter method. readonly Don’t synthesize a setter method. nonatomic Don’t guarantee the integrity of accessors in a multi-threaded environment. This is more efficient than the default atomic behavior.strong Create an owning relationship between the property and the assigned value. This is the default for object properties. weak Create a non-owning relationship between the property and the assigned value. Use this to prevent retain cycles. copy Create a copy of the assigned value instead of referencing the existing instance.
  • 46. • Methods represent the actions that an object knows how to perform. They’re the logical counterpart to properties, which represent an object’s data. You can think of methods as functions that are attached to an object; however, they have a very different syntax. Methods
  • 47. • Objective-C methods are designed to remove all ambiguities from an API. As a result, method names are horribly verbose, but undeniably descriptive. // Car.h ! // Accessors - (BOOL)isRunning; - (void)setRunning:(BOOL)running; - (NSString *)model; - (void)setModel:(NSString *)model; ! // Action methods - (void)startEngine; - (void)turnToAngle:(double)theAngle; ! // Constructor methods - (id)initWithModel:(NSString *)aModel; - (id)initWithModel:(NSString *)aModel mileage:(double)theMileage; ! // Factory methods + (Car *)car; + (Car *)carWithModel:(NSString *)aModel; Naming Conventions
  • 48. • Nesting method calls is a common pattern in Objective-C programs. It’s a natural way to pass the result of one call to another. Conceptually, it’s the exact same as chaining methods, but the square-bracket syntax makes them look a little bit different: Car *car = [[Car alloc]initWithModel:@"Honda Civic" mileage:400]; • First, the [Car alloc] method is invoked, then the init method is called on its return value. Nested Calling Methods
  • 49. • There are no protected or private access modifiers for Objective-C methods—they are all public. However, Objective-C does provide alternative organizational paradigms that let you emulate these features. Protected and Private Methods
  • 50. • Selectors are Objective-C’s internal representation of a method name. They let you treat a method as an independent entity, enabling you to separate an action from the object that needs to perform it. This is the basis of the Target-Action design pattern, and it is an integral part of Objective-C’s dynamic typing system. • There are two ways to get the selector for a method name. The @selector() directive lets you convert a source-code method name to a selector, and the NSSelectorFromString() function lets you convert a string to a selector (the latter is not as efficient). Both of these return a special data type for selectors called SEL. You can use SEL the exact same way as BOOL, int, or any other data type. Selectors
  • 51. // main.m ! Car *porsche = [[Car alloc] init]; porsche.model = @"Porsche 911 Carrera"; ! SEL stepOne = NSSelectorFromString(@"startEngine"); SEL stepTwo = @selector(driveForDistance:); ! // This is the same as: // [porsche startEngine]; [porsche performSelector:stepOne]; ! // This is the same as: // [porsche driveForDistance:[NSNumber numberWithDouble:5.7]]; [porsche performSelector:stepTwo withObject:[NSNumber numberWithDouble:5.7]]; Selectors
  • 52. Documentation Object-Oriented Programming with Objective-C https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/OOP_ObjC/Introduction/ Introduction.html Programming with Objective-C https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/ Introduction/Introduction.html
  • 54. Next: Object Oriented Programming with Objective-C (Part 2)