oops features using objective c

27
Tiyasi Acharya

Upload: tiyasi-acharya

Post on 22-Apr-2015

5.159 views

Category:

Technology


4 download

DESCRIPTION

There is an explanation of why OOPs and then there is detailing on how OOPs is used by Objective C.

TRANSCRIPT

Page 1: OOPS features using Objective C

Tiyasi Acharya

Page 2: OOPS features using Objective C

Why OOPs?

• Spaghetti code.• Mass of tangled jumps and conditional

branches.• Not designed for efficiency.

Page 3: OOPS features using Objective C

Performance

Complexity

Time/Size

Page 4: OOPS features using Objective C

Performance

Complexity

Time/Size

OOPs

Page 5: OOPS features using Objective C

How did OOPs come into the picture?

Abstraction

‘Emulate the working of a brain’ ‘Abstract out the details’

Page 6: OOPS features using Objective C
Page 7: OOPS features using Objective C

Internal Model of a Car

Page 8: OOPS features using Objective C

Internal Model of a Car

This is what computer scientists tried to bring into OOPs- ABSTRACTION!

Page 9: OOPS features using Objective C

Abstraction

Page 10: OOPS features using Objective C

AbstractionThis is how the human brain handles the complexity of the world.

Page 11: OOPS features using Objective C

AbstractionThis is how the human brain handles the complexity of the world.

How is this achieved in OOPs?

Page 12: OOPS features using Objective C

Inheritance

Super Class: Four-wheeler Vehicles

Sub Class: Truck, Car, Bus.

Process by which 1 object acquires the properties of another object.

Page 13: OOPS features using Objective C

Encapsulation

“Hides” incredible amount of complexity by encapsulating it.

Page 14: OOPS features using Objective C

Encapsulation

What was it hiding?

Page 15: OOPS features using Objective C

Polymorphism

Steering Wheel

Power Steering Wheel Steering wheel of an Electric car

A feature that allows 1 interface to be used for a general class of actions.

Page 16: OOPS features using Objective C

Another example of Polymorphism

Dog Smell

Page 17: OOPS features using Objective C

Class and Objects

Page 18: OOPS features using Objective C

OOPs in Objective C

Page 19: OOPS features using Objective C

Class and ObjectsA class consists of members: data and methods.

@interface Employee: NSObject{

int empId;char *name;

}

-(int) empId;-(int)lengthOfService:date;

@end

Class Name

Members: Data

Members: Methods

Page 20: OOPS features using Objective C

Objects

id date=[ [ Date alloc ] init ];

[ date release];

New Date object allocated

Releasing the variable

Page 21: OOPS features using Objective C

Inheritance

@interface Rectangle: NSObject{

int length;int width;

}

-(int) area;

@end

Superclass Rectangle.h #import “Rectangle.h”

@implementation Rectangle -(id) init{

if(self=[super init]){

length = 8;width = 5;

}return self;

}

-(int) area{

int area1=length * width;}@end

Superclass Rectangle.m

Page 22: OOPS features using Objective C

Inheritance

Subclass printAreaOfRectangle.h

Subclass printAreaOfRectangle.m

#import “Rectangle.h”

@interface printAreaOfRectangle: Rectangle

-(void) printVal;

@end

#import “printAreaOfRectangle.h”

@implementation printAreaOfRectangle(void) printVal{

NSLog(@”Area = %d”,[self area]);}@end

Page 23: OOPS features using Objective C

Encapsulation

• All the data members are ‘Protected’.• Data is encapsulated, can be accessed only through

setter/getter methods.

Page 24: OOPS features using Objective C

Polymorphism

main{

Window *W = [[Window alloc] init];View *V = [[view alloc] init];

[W flush];[V flush];

}

Page 25: OOPS features using Objective C

Dynamic binding + Message Passing

main{

Window *W = [[Window alloc] init];View *V = [[view alloc] init];

[W flush];[V flush];

id anotherObj = W;

[anotherObj flush]; }

Dynamic Binding

Message Passing

The flush message is passed to the variable anotherObj that is dynamically bound during runtime.

Page 26: OOPS features using Objective C

Summary

• Abstraction• Encapsulation• Class• Object• Inheritance• Polymorphism• Message passing• Dynamic Binding

The OOPs features that Objective C exhibits are as follows:

Page 27: OOPS features using Objective C

Thank you