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

What is the purpose of a delegation pattern?

Delegation is not exactly a ‘design pattern’ in the sense used in the GoF book. It is useful in a number of scenarios, and is a base for other patterns when you want to perform some additional actions before/after you delegate (that’s the Decorator pattern, but it’s based on delegation). For example, Collections.synchronizedList(..) creates a … Read more

Distinguishing between delegation, composition and aggregation (Java OO Design)

Delegation public class A { private B b = new B(); public void methodA() { b.methodB(); } } When clients of A call methodA, class A delegates the call to B‘s methodB. Rationale. Class A exposes behaviours that belong elsewhere. This can happen in single-inheritance languages where class A inherits from one class, but its … Read more

Implementing multiple interfaces with Java – is there a way to delegate?

As said, there’s no way. However, a bit decent IDE can autogenerate delegate methods. For example Eclipse can do. First setup a template: public class MultipleInterfaces implements InterFaceOne, InterFaceTwo { private InterFaceOne if1; private InterFaceTwo if2; } then rightclick, choose Source > Generate Delegate Methods and tick the both if1 and if2 fields and click … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)