From 9036f20b5fc16708504e29034a4011752205d984 Mon Sep 17 00:00:00 2001 From: rillk500 Date: Fri, 16 Oct 2020 21:56:05 +0600 Subject: [PATCH] Singleton Design Pattern --- lesson#22 - Singleton design pattern/ourGame/source/app.d | 1 + lesson#22 - Singleton design pattern/ourGame/source/data.d | 2 ++ .../ourGame/source/gstatemanager.d | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/lesson#22 - Singleton design pattern/ourGame/source/app.d b/lesson#22 - Singleton design pattern/ourGame/source/app.d index e393a01..6014269 100644 --- a/lesson#22 - Singleton design pattern/ourGame/source/app.d +++ b/lesson#22 - Singleton design pattern/ourGame/source/app.d @@ -13,6 +13,7 @@ void main() { // process events // update + // calling the dummy function GStateManager.getInstance().hello_world(); // render diff --git a/lesson#22 - Singleton design pattern/ourGame/source/data.d b/lesson#22 - Singleton design pattern/ourGame/source/data.d index f2fd6ae..2bf30ec 100644 --- a/lesson#22 - Singleton design pattern/ourGame/source/data.d +++ b/lesson#22 - Singleton design pattern/ourGame/source/data.d @@ -1,7 +1,9 @@ module data; +// mostly used libraries public import raylib; public import std.stdio: writeln, write; +// window dimensions immutable windowWidth = 720; immutable windowHeight = 640; diff --git a/lesson#22 - Singleton design pattern/ourGame/source/gstatemanager.d b/lesson#22 - Singleton design pattern/ourGame/source/gstatemanager.d index 90b2d99..897073f 100644 --- a/lesson#22 - Singleton design pattern/ourGame/source/gstatemanager.d +++ b/lesson#22 - Singleton design pattern/ourGame/source/gstatemanager.d @@ -1,10 +1,13 @@ import data; class GStateManager { + // private class instance private static GStateManager instance; + // private constructor private this() { } + // return the instance; create the instance, if it wasn't created yet static GStateManager getInstance() { if(instance is null) { instance = new GStateManager(); @@ -13,6 +16,7 @@ class GStateManager { return instance; } + // dummy function for testing purposes void hello_world() { writeln("Hello World!"); }