Skip to content

Instantly share code, notes, and snippets.

@enl
enl / 01-pure-immutable.php
Last active May 9, 2022 19:13
Immutable classes in PHP
/**
* This class is purely immutable.
* PHP protects the string from changing by its copy-on-change mechanics
* If you do `$str = $immutable->getField();` and then change `$str`
* PHP will copy the value and change only second one.
*/
class Immutable
{
/** @var string */
private $field;
@enl
enl / Cat.java
Created April 6, 2016 05:04
Cats constructor overload
class Color {}
class Address {}
class Cat {
private Int age;
private Double weight;
private String name;
private Address address;
private Color color;