No getter/setter on model with many instance vars While reading Object calisthenics and Getters/Setters. Evil. Period. I got confused. Let me explain it by example.

I have this organization class, representing the information about organization, the classic entity:

class Organization
{
    private $name;

    private $city;

    private $street;

    private $phone;

    private $email;

    public function __construct($name, $city, $street, $phone, $email)
    {
        $this-&gt;name = $name;
        $this-&gt;city = $city;
        $this-&gt;street = $street;
        $this-&gt;phone = $phone;
        $this-&gt;email = $email;
    }

    public function getName()
    {
        ....
    }

    public function getCity()
    {
        ....
    }

    public function setCity($newCity)
    {
        ....
    }

    public function getStreet()
    {
        ....
    }

    public function setStreet($newStreet)
    {
        ....
    }

    public function getPhone()
    {
        ....
    }

    public function getEmail()
    {
        ....
    }

    public function setPhone($newPhoneNumber)
    {
        ....
    }
}


The organization name, city, street, phone and email may change, so the setters looks kind a logical. Getters are used to to display the properties of organization in table. How can I remove the boilerplate code and break trough from this anemic model? Maybe this is the case where the getter/setter is unavoidable?

Also object initialization using __construct. Is it a good practice to pass so many instance variables to constructor?

I gave it a try, according to what I read. Created some ValueObject to store information and do validation (don't know if the ValueObject should do a validation on its data):

class Phone
{
    private $phone;

    public function __construct($phone)
    {
        if (!$this-&gt;validate($phone)) {
            throw new InvalidPhoneNumberException();
        }

        $this-&gt;phone = $phone;
    }

    public function getPhone()
    {
        return $this-&gt;phone;
    }

    private function validate($phone)
    {
        // validate the phone number
    }
}

class Email
{
    private $email;

    public function __construct($email)
    {
        if (!$this-&gt;validate($email)) {
            throw new InvalidEmailAddressException();
        }

        $this-&gt;email = $email;
    }

    public function getEmail()
    {
        return $this-&gt;email;
    }

    private function validate($email)
    {
        // validate email
    }
}


class Address
{
    private $city;

    private $street;

    public function __construct($city, $street)
    {
        $this-&gt;city= $city;
        $this-&gt;street = $street;
    }

    public function getCity()
    {
        return $this-&gt;city;
    }

    public function getStreet()
    {
        return $this-&gt;street;
    }
}


Then passed these objects instead of string representations of data to my Organization and did some renaming on methods:

class Organization
{
    private $name;

    private $address;

    private $phone;

    private $email;

    public function __construct($name, Address $address, Phone $phone, Email $email)
    {
        $this-&gt;name = $name;
        $this-&gt;address = $address;
        $this-&gt;phone = $phone;
        $this-&gt;email = $email;
    }

    public function getName()
    {
        return $this-&gt;name;
    }

    public function getAddress()
    {
        return $this-&gt;address;
    }

    public function getPhone()
    {
        return $this-&gt;phone;
    }

    public function getEmail()
    {
        return $this-&gt;email;
    }

    public function changeAddress(Address $newAddress)
    {
        $this-&gt;address = $newAddress;
    }

    public function changePhoneNumber(Phone $newPhoneNumber)
    {
        $this-&gt;phone = $newPhoneNumber;
    }
}


Does this code smells less and looks more mature from the perspective of OOP?
Getters and setters are not evil, period.

Mindlessly setting and getting fields of an object is bad, though. Especially with this syntax (setX, getX).

Simple example showing the difference between mindless and thoughtful setter :

# Mindless
class CartesianPoint {
    private $x;
    private $y;

    public function setX($x) {
        $this-&gt;x = $x;
    }

    public function setY($y) {
        $this-&gt;y = $y;
    }
}

# Thoughtful
class CartesianPoint {
    private $x;
    private $y;

    public function plot($x, $y) {
        $this-&gt;x = $x;
        $this-&gt;y = $y;
    }
}


Can you spot the differences ? You don't want to be able to only set X or Y location of a cartesian point, because that is not how it works.

Note that object is written in bold in the second sentence. Your Organization class is merely a data structure here. There's no sense attached to it, it doesn't follow rules and doesn't use its own logic.

In conclusion, if something has some logic/sense about it that the external world knows (should know) nothing about, make an object, but so far, Organization should only have public fields, and absolutely no methods inside. That's not an object.