Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Xelom
Xelom / csharpdeneme
Created December 12, 2013 11:27
c# deneme
using System;
List<string> myStrings = new List<string> { "ali", "veli", "ayşe" };
foreach(var myString in myStrings)
{
Console.Writeline(mystring);
}
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)
@Xelom
Xelom / simple-factory.md
Created February 22, 2017 13:01
Simple Factory

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 {
@Xelom
Xelom / factory-method.md
Created February 22, 2017 13:07
Factory Method

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!';
@Xelom
Xelom / abstract-factory.md
Created February 22, 2017 13:46
Abstract Factory

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';
@Xelom
Xelom / builder.md
Created February 22, 2017 13:51
Builder

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

@Xelom
Xelom / prototype.md
Created February 22, 2017 13:54
Prototype

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-&gt;category = $category;
@Xelom
Xelom / singleton.md
Created February 22, 2017 13:59
Singleton

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 {
{
"meta": { "theme": "classy" },
"basics": {
"name": "Arıl Bozoluk",
"label": "Software Engineering Manager",
"picture": "https://media.licdn.com/dms/image/C5603AQEuhtGb4uXoQg/profile-displayphoto-shrink_200_200/0?e=1572480000&v=beta&t=h8JHbAznqLKsr2XK9FTM6FO6pcv2zm71ADcoorW9g7o",
"email": "arilbozoluk@hotmail.com",
"phone": "(546) 223 17 23",
"website": "",
"location": {