Skip to content

Instantly share code, notes, and snippets.

View resume.json
"meta": { "theme": "classy" },
"basics": {
"name": "Arıl Bozoluk",
"label": "Software Engineering Manager",
"picture": "",
"email": "",
"phone": "(546) 223 17 23",
"website": "",
"location": {

To create a singleton, make the constructor private, disable cloning, disable extension and create a static variable to house the instance

final class President {
    private static $instance;

    private function __construct() {
        // Hide the constructor
    public static function getInstance() : President {

In PHP, it can be easily done using clone

class Sheep {
    protected $name;
    protected $category;

    public function __construct(string $name, string $category = 'Mountain Sheep') {
        $this->name = $name;
        $this->category = $category;

Having said that let me add a bit about what telescoping constructor anti-pattern is. At one point or the other we have all seen a constructor like below:

public function __construct($size, $cheese = true, $pepperoni = true, $tomato = false, $lettuce = true) {

As you can see; the number of constructor parameters can quickly get out of hand and it might become difficult to understand the arrangement of parameters. Plus this parameter list could keep on growing if you would want to add more options in future. This is called telescoping constructor anti-pattern.

Programmatic Example


Translating the door example above. First of all we have our Door interface and some implementation for it

interface Door {
    public function getDescription();

class WoodenDoor implements Door {
    public function getDescription() {
        echo 'I am a wooden door';

Taking our hiring manager example above. First of all we have an interviewer interface and some implementations for it

interface Interviewer {
    public function askQuestions();

class Developer implements Interviewer {
    public function askQuestions() {
        echo 'Asking about design patterns!';

Programmatic Example

First of all we have a door interface and the implementation

interface Door {
    public function getWidth() : float;
    public function getHeight() : float;

class WoodenDoor implements Door {
from collections import MutableSequence
import marshal
from operator import add, div, mul, neg, mod, sub
from operator import ge, gt, le, lt, eq
from itertools import imap
Extended list class
- fast lookups by maintaining a dictionary with the values
- numeric operations between 2 instances are possible (like Octave matrices)
View csharpdeneme
using System;
List<string> myStrings = new List<string> { "ali", "veli", "ayşe" };
foreach(var myString in myStrings)
You can’t perform that action at this time.