From 3f66f074d5716aaacdfea6a974ed0f11b2169ef1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 8 Dec 2014 03:26:54 +0100 Subject: [PATCH] Wrap bullet list --- pages/Design-Patterns.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pages/Design-Patterns.md b/pages/Design-Patterns.md index 77d0349..d3856e5 100644 --- a/pages/Design-Patterns.md +++ b/pages/Design-Patterns.md @@ -1,6 +1,6 @@ --- layout: page -title: Design Patterns +title: Design Patterns --- # Design Patterns @@ -134,10 +134,16 @@ var_dump($anotherObj === SingletonChild::getInstance()); // bool(true) The code above implements the singleton pattern using a [*static* variable](http://php.net/language.variables.scope#language.variables.scope.static) and the static creation method `getInstance()`. Note the following: -* The constructor [`__construct`](http://php.net/language.oop5.decon#object.construct) is declared as protected to prevent creating a new instance outside of the class via the `new` operator. -* The magic method [`__clone`](http://php.net/language.oop5.cloning#object.clone) is declared as private to prevent cloning of an instance of the class via the [`clone`](http://php.net/language.oop5.cloning) operator. -* The magic method [`__wakeup`](http://php.net/language.oop5.magic#object.wakeup) is declared as private to prevent unserializing of an instance of the class via the global function [`unserialize()`](http://php.net/function.unserialize). -* A new instance is created via [late static binding](http://php.net/language.oop5.late-static-bindings) in the static creation method `getInstance()` with the keyword `static`. This allows the subclassing of the class `Singleton` in the example. +* The constructor [`__construct`](http://php.net/language.oop5.decon#object.construct) is declared as protected to +prevent creating a new instance outside of the class via the `new` operator. +* The magic method [`__clone`](http://php.net/language.oop5.cloning#object.clone) is declared as private to prevent +cloning of an instance of the class via the [`clone`](http://php.net/language.oop5.cloning) operator. +* The magic method [`__wakeup`](http://php.net/language.oop5.magic#object.wakeup) is declared as private to prevent +unserializing of an instance of the class via the global function [`unserialize()`](http://php.net/function.unserialize) +. +* A new instance is created via [late static binding](http://php.net/language.oop5.late-static-bindings) in the static +creation method `getInstance()` with the keyword `static`. This allows the subclassing of the class `Singleton` in the +example. The singleton pattern is useful when we need to make sure we only have a single instance of a class for the entire request lifecycle in a web application. This typically occurs when we have global objects (such as a Configuration