static void Main(string[] args) { // Behavioural examples var strategy = new StrategyExample(); strategy.RunExample(); var chain = new ChainOfResponsibilityExample(); chain.RunExample(); var memento = new MementoExample(); memento.RunExample(); // Creational examples var singleton = new SingletonExample(); singleton.RunExample(); var builder = new BuilderExample(); builder.RunExample(); // Structural examples var adapter = new AdapterExample(); adapter.RunExample(); }
// Use this for initialization void Start() { singleton = SingletonExample.instance; singleton.health += 20; // using health attribute "SET" Debug.Log(singleton.health); // using health attribute "GET" StartCoroutine(singleton.LoadNextScene("OtherScene", 1.5f)); }
static void Main(string[] args) { //SingletonExample ap1 = new SingletonExample(); private SingletonExample ap1 = SingletonExample.airport(); string hava1 = ap1.HavaYolu(); Console.WriteLine(hava1); }
// This is the static method that controls the access to the singleton // instance. On the first run, it creates a singleton object and places // it into the static field. On subsequent runs, it returns the client // existing object stored in the static field. public static SingletonExample GetInstance() { if (_instance == null) { _instance = new SingletonExample(); } return(_instance); }
//lazy construction of the instance public static SingletonExample getInstance() { if (uniqueInstance == null) { uniqueInstance = new SingletonExample(); } return(uniqueInstance); }
static void Main(string[] args) { SingletonExample sg = SingletonExample.SeInstance; Console.WriteLine(sg.GetMessages().SingleOrDefault()); Console.ReadKey(); //Connection con = Connection.Instance; //Console.WriteLine(con.GetAllUsers().SingleOrDefault(c => c.Key == "TanaseA").Value.Name.ToString()); //Console.ReadKey(); }
public void When_CorrectData_Expect_Success() { // Arrange var singletonExample = new SingletonExample(); // TODO dependency injection? also moq // Act singletonExample.RunExample(); // Assert // TODO }
public void Test_Instance_ReturnsTheSameInstance_WhenCalledTwice() { // Arrange SingletonExample resultOne = SingletonExample.Instance(); SingletonExample resultTwo = SingletonExample.Instance(); // Act // Assert Assert.AreEqual(resultOne, resultTwo); }
private void Awake() { if (_instance != null && _instance != this) { Debug.Log("An instance already exists, destroying"); Destroy(this.gameObject); } else { _instance = this; } }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> void Awake() { // singleton pattern if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
private void Awake() { if (_instance != null && _instance != this) { //If you reload same scene, this will make sure you only have one. DestroyImmediate(this.gameObject); } else { _instance = this; //if you wanna keep this object on another scene this will make it happen. //if you don't wanna move it to different scene, remove "DontDestroyOnLoad" DontDestroyOnLoad(this.gameObject); } }
public static void Main() { // Obtain reference to singleton and invoke methods. SingletonExample s = SingletonExample.Instance; s.SomeMethod1(); // Execute singleton functionality without a reference. SingletonExample.Instance.SomeMethod2(); // Wait to continue. Console.WriteLine(Environment.NewLine); Console.WriteLine("Main method complete. Press Enter"); Console.ReadLine(); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != this) { GenericUIManager.ChangeText("Singleton Instance already exists!"); Destroy(gameObject); } DontDestroyOnLoad(gameObject); }
void Awake() { // first found instance if (_instance == null) { _instance = this; DontDestroyOnLoad(_instance.gameObject); } else { // Destroy the rest if (this != _instance) // single line condition does not need {}; { Destroy(this.gameObject); } } }
// Nesne oluşturmadan kullanabilmek için. public static SingletonExample airport() { if (Airport == null) Airport = new SingletonExample(); return Airport; }
// Use this for initialization void Start() { singleton = SingletonExample.instance; Debug.Log(singleton.health); // calling health attribute get on our singleton }
// Start is called before the first frame update void Start() { singleton = this; }
static SingletonExample() { singleInstance = new SingletonExample(); }
static void printSecond() { SingletonExample sExample2 = SingletonExample.Instance; sExample2.PrintMessage("SECOND"); }
static void printFirst() { SingletonExample sExample1 = SingletonExample.Instance; sExample1.PrintMessage("FIRST"); }
static void Main(string[] args) { SingletonExample.Show(); }
/// <summary> /// 創建-單例模式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Singleton_button_Click(object sender, EventArgs e) { //進行單例模式的負載平衡模擬 SingletonExample Creational = new SingletonExample(); }