徒手空拳な技術系の生き様を綴る
Amebaでブログを始めよう!

Singleton

Singletonの一番簡単なクラスは

class Singleton{

praivte static $instance;

praivte function __construct(){

}

public static functin getInstance(){
if(isset(self::$instance)){
self::$instance = new Singleton()
}
}

public final functin __clone(){
throw new RuntimeException('Clone Is Not',get_class($this));

}
}

phpはclone対策が必要

デザインパターンの初歩の初歩

デザインパターンは元々は建築家が提唱した物でそれをソフトウェア設計に転用したもの


現在、有名なのはGoFパターンが有名(GoF: Gang of Four 四人のギャング)
GoFはデザインパターン23個を3つの目的に分類している


オブジェクトの生成に関するパターン
Abstract Factory
Builder
Factory Moethod
Prototype
Singleton


プログラムの構造に関するパターン
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy


オブジェクトの振る舞いに関するパターン
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template Mothod
Visitor