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/

Eeb061c8b2816b771920da1b3e7904a3?s=128

Swift India

June 03, 2018
Tweet

Transcript

  1. Protocol Oriented Programming With Swift

  2. Classes are great Encapsulation Inheritance Abstraction Extensibility

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

    UIManagedDocument UIApplication UIView Lets look at an example
  4. Problems with classes Implicit sharing A B Data Pony B

    needs its data not Ponies
  5. 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
  6. Does not apply to Swift Values don’t share

  7. 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
  8. Lets try to solve all these problems rather then learning

    to live with them.
  9. Swift is a Protocol Oriented Programming Language