Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

OOPS features using Objective C


Published on

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

Published in: Technology
  • Be the first to comment

OOPS features using Objective C

  1. 1. Tiyasi Acharya
  2. 2. Why OOPs?• Spaghetti code.• Mass of tangled jumps and conditional branches.• Not designed for efficiency.
  3. 3. PerformanceTime/Size Complexity
  4. 4. Performance OOPsTime/Size Complexity
  5. 5. How did OOPs come into the picture? Abstraction‘Emulate the working of a brain’ ‘Abstract out the details’
  6. 6. Internal Model of a Car
  7. 7. Internal Model of a CarThis is what computer scientists tried to bring into OOPs- ABSTRACTION!
  8. 8. Abstraction
  9. 9. AbstractionThis is how the human brain handles the complexity of the world.
  10. 10. AbstractionThis is how the human brain handles the complexity of the world. How is this achieved in OOPs?
  11. 11. InheritanceProcess by which 1 object acquires the properties of another object. Super Class: Four-wheeler Vehicles Sub Class: Truck, Car, Bus.
  12. 12. Encapsulation“Hides” incredible amount of complexity by encapsulating it.
  13. 13. EncapsulationWhat was it hiding?
  14. 14. PolymorphismA feature that allows 1 interface to be used for a general class of actions. Steering Wheel Power Steering Wheel Steering wheel of an Electric car
  15. 15. Another example of Polymorphism Dog Smell
  16. 16. Class and Objects
  17. 17. OOPs in Objective C
  18. 18. Class and ObjectsA class consists of members: data and methods. Class Name@interface Employee: NSObject{ int empId; char *name; Members: Data}-(int) empId; Members: Methods-(int)lengthOfService:date;@end
  19. 19. Objectsid date=[ [ Date alloc ] init ]; New Date object allocated[ date release]; Releasing the variable
  20. 20. Inheritance Superclass Rectangle.m #import “Rectangle.h” Superclass Rectangle.h @implementation Rectangle@interface Rectangle: NSObject{ -(id) init int length; { int width; if(self=[super init])} { length = 8;-(int) area; width = 5; }@end return self; } -(int) area { int area1=length * width; } @end
  21. 21. InheritanceSubclass printAreaOfRectangle.h#import “Rectangle.h”@interface printAreaOfRectangle: Rectangle-(void) printVal;@end Subclass printAreaOfRectangle.m #import “printAreaOfRectangle.h” @implementation printAreaOfRectangle (void) printVal { NSLog(@”Area = %d”,[self area]); } @end
  22. 22. Encapsulation• All the data members are ‘Protected’.• Data is encapsulated, can be accessed only through setter/getter methods.
  23. 23. Polymorphismmain{ Window *W = [[Window alloc] init]; View *V = [[view alloc] init]; [W flush]; [V flush];}
  24. 24. Dynamic binding + Message Passing main { Window *W = [[Window alloc] init]; View *V = [[view alloc] init]; [W flush]; [V flush]; id anotherObj = W; Dynamic Binding [anotherObj flush]; Message Passing }The flush message is passed to the variable anotherObj that is dynamically bound during runtime.
  25. 25. SummaryThe OOPs features that Objective C exhibits are as follows: • Abstraction • Encapsulation • Class • Object • Inheritance • Polymorphism • Message passing • Dynamic Binding
  26. 26. Thank you