Other Languages

Php Design Patterns, Singleton Pattern

Single instance for a class instantiation
Private keyword hides the class constructor for outside

class MyClass
  private static $INSTANCE
  public static function getInstance()
    return self::INSTANCE
Static



Java

Java OOP, Static Keyword

Static variables, initialized only once
Methods, belongs to class, not to instance 

static int count;
static long myRound(Double n)
  return Math.round(n)
Static

Java Effective, Constructors

Static factory, a static instance
Telescoping, JavaBeans, Builder

static A INSTANCE = new A()
new A(240); new A(240, 100)
Static

Java Effective, Import Static

Import static, to avoid qualifying
Potential negative impact on readabilty

import static java.lang.Math.PI
assertEquals(PI == Math.PI, true)
Static

Java Lambdas, Static Methods

Java 8 allows static methods in interfaces
Method reference, call methods on its parameter
 
abstract interface A<T> extends Stream<T>
  static <T> Stream<T> of(T... values) {}
A.stream().map(String::toUpperCase)
Static