Logo 
Search:

Design Pattern Video

Submit Video
Home » Videos » Design Pattern

Design Pattern - Singleton Parte #1

  Shared By: JwcelyoBr      Date: Sep 19      Category: Design Pattern     
In software engineering, the singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects (say, five). Some consider it an anti-pattern, judging that it is overused, introduces unnecessary limitations in situations where a sole instance of a class is not actually required, and introduces global state into an application.[1][2][3][4][5][6] In C++ it also serves to isolate from the unpredictability of the order of dynamic initialization, returning control to the programmer. Implementation Implementation of a singleton pattern must satisfy the single instance and global access principles. It requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected (not private, because reuse and unit test could need to access <b>...</b>
 
Share: 

Didn't find what you were looking for? Find more on Design Pattern - Singleton Parte #1 Or get search suggestion and latest updates.

 

Related Videos