🎞️ ACTIONSCRIPT WARD DIFFICULTY: Apprentice Creational

The Singleton

Ensuring only one dark Overlord exists in the AVM2 instance.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // State Monopoly
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ACTIONSCRIPT PATTERN //
package arcana.singleton {

    public class StageOverlord {
        private static var _instance:StageOverlord;
        private static var _allowInstantiation:Boolean = false;

        public var darkAuraRadius:Number = 666.0;

        public function StageOverlord() {
            if (!_allowInstantiation) {
                throw new Error("Direct instantiation forbidden. Use StageOverlord.getInstance().");
            }
            trace("The Stage Overlord has awakened.");
        }

        public static function getInstance():StageOverlord {
            if (_instance == null) {
                _allowInstantiation = true;
                _instance = new StageOverlord();
                _allowInstantiation = false;
            }
            return _instance;
        }

        public function corruptStage():void {
            trace("The stage is now corrupted by the Overlord's presence.");
        }
    }
}
Runic Tags: #singleton #actionscript #flash #overlord