What is Protocol Oriented Programming in Swift? What added value does it bring?

Preface: POP and OOP are not mutually exclusive. They’re design paradigms that are greatly related. The primary aspect of POP over OOP is that is prefers composition over inheritance. There are several benefits to this. In large inheritance hierarchies, the ancestor classes tend to contain most of the (generalized) functionality, with the leaf subclasses making … Read more

Why aren’t superclass __init__ methods automatically invoked?

The crucial distinction between Python’s __init__ and those other languages constructors is that __init__ is not a constructor: it’s an initializer (the actual constructor (if any, but, see later;-) is __new__ and works completely differently again). While constructing all superclasses (and, no doubt, doing so “before” you continue constructing downwards) is obviously part of saying … Read more

What is a C++ delegate?

You have an incredible number of choices to achieve delegates in C++. Here are the ones that came to my mind. Option 1 : functors: A function object may be created by implementing operator() struct Functor { // Normal class/struct members int operator()(double d) // Arbitrary return types and parameter list { return (int) d … Read more

Delegates in swift?

Here’s a little help on delegates between two view controllers: Step 1: Make a protocol in the UIViewController that you will be removing/will be sending the data. protocol FooTwoViewControllerDelegate:class { func myVCDidFinish(_ controller: FooTwoViewController, text: String) } Step2: Declare the delegate in the sending class (i.e. UIViewcontroller) class FooTwoViewController: UIViewController { weak var delegate: FooTwoViewControllerDelegate? … Read more