Pivot Tables

I think the Laravel developers don’t know what a Pivot Table is. At the time of writing:

If you need to define attributes that should be set on the pivot / intermediate table linking the models, you may use the hasAttached method. This method accepts an array of pivot table attribute names and values as its second argument

The concept they’re looking for is Association Table.
Oh, look. I just noticed this on the Wikipedia article: “pivot table (as used incorrectly in Laravel – not to be confused with the correct use of pivot table in spreadsheets)”; so this has already been discovered.

Factory specialization

I just knocked this up to confirm my thinking was right:

<?php

class StdFeature {

}

class AppFeature extends StdFeature {

}

class FactoryBase {

  public function new_feature() : StdFeature { return new StdFeature; }

}

class Factory extends FactoryBase {

  public function new_feature() : AppFeature { return new AppFeature; }

}

$factory = new Factory();

$feature = $factory->new_feature();

assert( is_a( $feature, 'AppFeature' ) );

How To Design A Good API and Why it Matters

Today I watched: How To Design A Good API and Why it Matters. Good talk. Favourite quote:

Inheritance violates encapsulation

Oh, and I followed on with: A Brief, Opinionated History of the API wherein (t=28:14) Bloch says it’s an API if you can answer yes to both of these:

  1. Does it provide a set of operations defined by their inputs and outputs?
  2. Does it admit reimplementation without compromising its users?