RazeSoldier
I am learning software design patterns, and I find this problem: What is the difference between pure static class and class using singleton pattern?
Glossary
Pure static class
Class consisting of static methods and static properties
Class using singleton pattern
See Singleton pattern.
Example code
Pure static class
class Config {
private static $configs = [];
public static function get($config) {
return self::$config[$config];
}
}
Class using singleton pattern
class Config {
private $configs = [];
private static $instance;
private function __construct();
public function get($config) {
return $this->config[$config];
}
public static function getInstance() {
if ( self::$instance === null ) {
self::$instance = new self;
}
return self::$instance;
}
}