hurricane / driver-php

PHP driver for Hurricane
gethurricane.org
7 stars 0 forks source link

Erlang\DataType's do not respect Open Close principle. #3

Closed HelloGrayson closed 12 years ago

HelloGrayson commented 12 years ago

Models should be open for extension but closed for modification. Specifically, this means accessing properties on these data types through getters. This will aid in unit testing them as well because objects should have their public API tested; testing public properties is bad practice.

<?php

class Model
{
    public $name;
}

The above is ridiculously fragile and strange to test. Below is correct.

<?php

class Model
{
    private $name;
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = (string) $name;
    }
}

class ModelTest
{
    public function testNameShouldBeBob()
    {
        $name = 'bob';
        $subject = new Model();
        $subject->setName($name);
        $this->assertEqual($name, $subject->getName());
    }
}
icheishvili commented 12 years ago

For most data types, we can just implement getters/setters, grep/replace occurrences and call it a day.

HelloGrayson commented 12 years ago

sure - we'll also want to lock down visibility of properties and methods where possible, less things to test etc.

icheishvili commented 12 years ago

Erlang\DataType's do not respect Open Close principle..... they do now :)

HelloGrayson commented 12 years ago

Badass - getting nice and tight.