Fraternity Manuals

Natural API's

From ActiveModel

Natual API's are a way of describing an api that is inherent to the developer. Without the use of an apidoc, manual, or IDE auto-completion; the developer can EXPECT a model's accessor api by simply knowing the table structure or model definition.

Models

For example, if we have the following table (assuming an SQL connector):


CREATE TABLE people
(
id int(11) unsigned NOT NULL auto_increment,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
birthdate date default NULL,
PRIMARY KEY (id)
)

The developer can expect the following api calls to be valid:


$p = new Person();
$p->setFirstName('John');
$p->setLastName('Smith');
$p->save();

// or later

$p = new Person(5);  // person with id 5
echo $p->getLastName() . ', ' . $p->getFirstName();

Navigation
MediaWiki