Posts

Showing posts with the label iosdev

Design Patterns & Principles - Strategy Pattern

This is a part of a blogpost series listing the design principles and pattern definitions. The Strategy Pattern - defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets algorithm vary independently from clients that use it. Following are few principles adhered in this pattern Identify the aspect of your application that vary and separate them from what stays same. Program to interface not to an implementation Favor composition over inheritance The example code for strategy pattern in Swift is available at my github repo . courtesy: Head First Design Patterns

Protocol oriented programming PoP

This post is a part of my blogpost series while learning Swift and Programming paradigms. First part on Functional Programming can be found here . Protocol oriented programming (POP)  can be said as as - a way to adhere the " Program to interface not to implement " principle  - which is one of the basic design principles of software development. Structure your code such that you define interfaces first then make the classes implement it. Define interfaces using protocols and then make classes implement them. POP is just another technical term for the interface programming in Swift programming language. Yes! There are additional advantages of POP in swift using "Extensions" along with protocols in Swift. Let us discuss this with a classic example - Shapes and its classes . Any shape has area. Every shape needs to be drawn on some canvas. Typically an average programmer thinks: Let's have a base class named Shape. Let's derive all other concr...

Functional programming concept and Swift

Image
For quite sometime now I am on a new programming language from Apple - Swift. Apart from the hype Swift got there are multiple programming paradigms that I got introduced to - Functional Programming ( FP ), Protocol oriented programming ( PoP ). I was little curious as I knew what functions are and what protocols are used for especially in objective-C, and my mind asked me few questions - What are Functional Programming and Protocol oriented programming? Is swift a Functional Programming language or a Protocol oriented programming language? Is it mandatory to learn in Functional Programming or Protocol oriented programming to code in Swift? What is the right way? Browsing through some websites and reading few books, this is what I understand. In this post I will be sharing my thoughts & understanding on FP and a subsequent post on PoP. Q: What is Functional Programming? Answer:  (In non-dev...