People Innovation Excellence
 
Feature Image

The Approach of Protocol Oriented Programming in MVVM model

Protocol Oriented Programming is a modified programming paradigm of object oriented programming introduced by Apple in 2015. Protocol Oriented Programming is similar to the interface in object oriented programming, where the protocols acts as a contract that defines methods, properties and other requirements needed to perform particular tasks. Protocol act as a contract because any type that adapts protocol promises to implement all requirements defined in the protocol. Protocol allow developers to write flexible and extensible code in Swift without having compromise with the language syntax or expression.

The idea behind implementing protocol oriented into MVVM (Model-View-ViewModel) is avoid the bad implementation and the code smells of MVC or MVVM model.

As shown in the picture 1.1, the implementation of Protocol Oriented in MVVM, greatly reduces number of duplicated functionality in the View-Model since each protocol has their own body or logic to be implemented by the needed View Controller such as ViewController11 and ViewController22, where both of the controllers need to implement the same function with the same logic.

 

References 

http://iosbrain.com/blog/2018/03/28/protocol-oriented-programming-in-swift-is-it-better-than-object-oriented-programming/

https://www.toptal.com/swift/introduction-protocol-oriented-programming-swift

https://docs.swift.org/swift-book/LanguageGuide/Protocols.html

Author : William 1901493415
Supervisor : Hanry Ham


Published at : Updated
Written By
Hanry Ham, S.Kom., M.Eng
Subject Content Coordinator Software Development | School of Computer Science

Periksa Browser Anda

Check Your Browser

Situs ini tidak lagi mendukung penggunaan browser dengan teknologi tertinggal.

Apabila Anda melihat pesan ini, berarti Anda masih menggunakan browser Internet Explorer seri 8 / 7 / 6 / ...

Sebagai informasi, browser yang anda gunakan ini tidaklah aman dan tidak dapat menampilkan teknologi CSS terakhir yang dapat membuat sebuah situs tampil lebih baik. Bahkan Microsoft sebagai pembuatnya, telah merekomendasikan agar menggunakan browser yang lebih modern.

Untuk tampilan yang lebih baik, gunakan salah satu browser berikut. Download dan Install, seluruhnya gratis untuk digunakan.

We're Moving Forward.

This Site Is No Longer Supporting Out-of Date Browser.

If you are viewing this message, it means that you are currently using Internet Explorer 8 / 7 / 6 / below to access this site. FYI, it is unsafe and unable to render the latest CSS improvements. Even Microsoft, its creator, wants you to install more modern browser.

Best viewed with one of these browser instead. It is totally free.

  1. Google Chrome
  2. Mozilla Firefox
  3. Opera
  4. Internet Explorer 9
Close