Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Protocol Oriented Programming

Protocol Oriented Programming

In the Protocol-Oriented approach, we start designing our system by defining protocols. We rely on new concepts: protocol extensions, protocol inheritance, and protocol compositions. The paradigm also changes how we view semantics. In Swift, value types are preferred over classes. However, object-oriented concepts don’t work well with structs and enums: a struct cannot inherit from another struct, neither can an enum inherit from another enum. In this tutorial, you’ll explore the ways you can create and use protocols, as well as use protocol-oriented programming patterns to make your code more extensible.
Code Example: https://github.com/nishiths23/POPDemo

Nishith Singh is from BookMyShow with 4.5 yrs of exp in iOS industry. He has immense interest & worked with RxSwift, HLS, Image & Video processing & many more. Further, he likes to travel and is a gym freak.

Presented at Swift Mumbai - Chapter #4 Meetup: https://www.meetup.com/Swift-Mumbai/events/250189683/

Swift India

June 03, 2018
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. Inheritance is awesome NSObject UIBarItem UIDocument UIResponder UIBarButtonItem UIT abBarItem

    UIManagedDocument UIApplication UIView Lets look at an example
  2. Now to solve this problem Defensive copying Inefficient Race conditions(Because

    of dispatch queues which leads to threads sharing mutable data) Locks More Inefficiency Deadlock Complexity Bugs @property (nonatomic, strong) Not news to us
  3. More problems with classes No multiple inheritance Get bloated as

    anything that is related is a part Have to choose superclass at declaration time, not later in some extension Have to inherit designated initializers