… a mixin is a class that contains methods for use by other classes without having to be the parent class of those other classes. …

… Mixins encourage code reuse and can be used to avoid the inheritance ambiguity that multiple inheritance can cause, or to work around lack of support for multiple inheritance in a language. A mixin can also be viewed as an interface with implemented methods.

Classes

Fundamental principles of OOP

Inheritance

Allows a class to override or extend the functionality of a base class.

Abstraction

Allows complex logic to be abstracted out. Achieved using interfaces and abstract classes.

Abstract classes

– Cannot be instantiated.
– It defines or partially implements the methods for any class that extends it.
– An abstract method cannot have an implementation.
– Any class that inherits from an abstract class, all abstract methods must be implemented by the derived class or they must be declared abstract.
– Unlike interfaces, abstract classes may have methods with full implementation and may also have defined member fields.

Interface

– An interface is not a class.
– Interfaces join types that are unrelated.
– Can only define method names, has no implementation.
– Any class that implements an interface must implement all the methods it defines or it must be declared abstract.

Difference between abstraction and interface

Encapsulation

Encapsulation hides the implementation details of a class from the object. In Encapsulation, the data is not accessed directly; it is accessed through the functions present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible.

Polymorphism

Polymorphism is the process of using function in different ways for different object types (method overriding).

A class can implement many interfaces and inherit only one class (even if that class is abstract)

Excellent article on PHP OOP:
http://zetcode.com/lang/php/oopi/
http://www.introprogramming.info/english-intro-csharp-book/read-online/chapter-20-object-oriented-programming-principles/#_Toc362296568 (For C# but the concepts are the same)

Here’s something new I learned today. I was trying to clean up some stale branches but Tower only deletes one at a time even if you selected multiple of them! Well, that’s annoying. So I started searching on the internet and this seems to work:

List all the branches that have the ‘PREFIX’ prefix. This is just to preview the list before deleting it.

$ git branch -r | awk -F/ '/\/PREFIX/{print $2}'

Note: -r shows all the remote branches. -a shows both local and remote.

If it looks good, delete away! (Scroll to see the command as it is pretty long)

For a while, I have been confused with all the different package managers that are floating around. NPM, Bower, Composer, Homebrew are some of the popular ones that I have used at work. So what are they and how do they differ from each other?

bower – Package manager for front-end web projects. It manages components that contain HTML, CSS, JavaScript, fonts or even image files. It is also an npm package (You will need npm and nodejs to install bower and to execute it. See Getting started with Bower.)

composer – Dependency manager for php projects (I have used this to install/update dependencies for Drupal sites)

Homebrew – Package manager for Mac OS X

And here is one of the ways how they cross paths with each other:
1) Install Homebrew (I use a Mac)
2) Use Homebrew to install node (It can also be downloaded from https://nodejs.org/en/, in that case – skip Step 1)
3) Install Bower with npm

npm install -g bower

4) Install jQuery with Bowerbower install jquery

Please note that Bower is not needed to install Javascript libraries – NPM can do the same. There are some articles on the web that talk about the drawbacks of using Bower:

Summarized from this article:
– PEAR installs dependencies globally and Composer installs them locally, in your project structure.
– PEAR is essentially a package manager and Composer is a dependency manager.

To install Composer, run:

curl -sS https://getcomposer.org/installer | php

To configure Composer:
– Create a file named composer.json in project root.
– Add dependencies to composer.json like this: