In the book "Java and Patterns" of Dr. Shanhong, this describes the singleton pattern: As an object's creation mode, Singleton mode ensures that a class has only one instance, and instantiates itself and provides this instance to the system as a whole. This class is called a singleton class.Structure of the Singleton patternthe characteristics of the singleton mode:
A singleton class can have only one instance.
The Singleton class must create its own unique instance.
The Single
In the book "Java and Patterns" of Dr. Shanhong, this describes the singleton pattern: As an object's creation mode, Singleton mode ensures that a class has only one instance, and instantiates itself and provides this instance to the system as a whole. This class is called a singleton class.
Structure of the Singleton patternthe characteristics of the singleton mode:
A singleton class can have only one instance.
The Singleton class must create its own unique instance.
The
Reprint reference: http://www.cnblogs.com/V1haoge/p/6510196.htmlThe so-called Singleton, refers to a single instance, there is only one class instance, this singleton should not be controlled by the person, but should be limited by the code, mandatory Singleton.Singleton has its own unique use scenario, generally for those business logic can only be limited to a single case, for example: similar to the existence of counters, and generally need to use an instance to record, if the multi-sample co
thinking from Java single example and single case
Objective
A few days ago accidentally saw an article, talked about the cliché of a single example, holding a review of the mentality points in, or those familiar with the content, but found himself thinking of the angle changed, before more is to remember, only stay on the surface, and now more is to think why would do so. So today I'm going to summarize the common examples in Java and write down my own thoughts. 2 text
Some of the common type
The single example pattern presumably everybody already very familiar with, usually its realization way divides into the following two kinds:
Copy Code code as follows:
The lazy type realizes
public class singleton{
private static Singleton instance = NULL;
Private Singleton () {}
public static newinstance () {
if (null = = Instance) {
Instance = new Singleton ();
}
return instance;
}
public void dosomething () {
Do something ...
}
}
A
The characteristics of the singleton mode: A singleton class can have only one instance. The Singleton class must create its own unique instance. The Singleton class must provide this instance to all other objects.
a hungry man single-case class
public class Eagersingleton {private static Eagersingleton instance = new Eagersingleton ();/** * Private Default construction child*/Private Eagersingleton () {}/** * Static Factory method*/public st
Design mode:The most effective way to solve a class of problems, 23 design patterns in Java.Singleton design Mode (Singleton): Resolves a class that only has one object in memoryFor example, when you use the same configuration information object for multiple programs, you need to guarantee the uniqueness of the object.To ensure that the object is unique:In order to avoid the creation of such objects by other programs, it is forbidden to establish such objects by other programs;It is also necessa
In Java, a singleton pattern typically has 2 categories of a hungry man patterns and lazy patterns.A hungry man mode refers to a singleton instance that was created when the class was loaded.The lazy way value is that a singleton instance is created when it is first used.Both a hungry man and lazy patterns use a static member variable to hold a real instance. and
Singleton mode Everyone is not unfamiliar, also know that it is divided into why lazy, a hungry man-style and so on. But is your understanding of the singleton pattern thorough enough? Today I take you to look at my eyes of the singleton, may be different from your understanding.Here's a simple little example:[Java] View plaincopyprint?
Simple lazy Type
Public class Singleton {
// Singleton case variable
private static Singleton instance
class must be defined before it can be used. The class is the template that creates the object, and the object that is created is also called the instantiation of the class.Here's a simple example to understand the definition of a class in Java:1 Public classdog{2 String name;3 intAge ;4 5 voidBark () {//Barking6System.out.println ("Bark, don't come over");7 }8 9 voidHungry () {//HungerTenSystem.out.println ("Master, I'm hungry.")
One of the simplest design patterns used in Android development, especially one that was often asked in the initial interview:Article Two: Singleton modeSingleton mode is available when you need to control only one instance of a class, and the customer can only access it from one global access point.There are two types of singleton mode: a hungry man type and lazy type .1, a hungry man type:Package com.hong
Before you learn this singleton mode, please choose to read another design mode
PHP design mode-Simple Factory mode (static Factory method mode)
PHP design mode-factory method mode (polymorphism Factory mode) (virtual construction sub-mode)
PHP design mode-Abstract Factory mode
As an object's creation mode, Singleton mode ensures that a class has only one instance, and instantiates it itself and provides it to the entire system, a class called a singleton classThe singleton mode
; A.hello () hello. I am A.Because Class B does not have a Hello method, Class B inherits the Class A, so the Class A Hello method is called.The most basic way to add functionality to a subclass is to add a method. However, you can also override some superclass methods to customize the behavior of the inheritance. As follows:Class A: def hello (self): print ' Hello. I am A. ' Class B (a): def hello (self): print ' Hello. I am b ' >>> B = B () >>> B.hello () hello. I am BSpe
In fact, when it comes to immersion status bar this name I also feel very helpless, I really do not know who this term is first launched. Because the Android authorities never gave a name like the immersive status bar, only the immersive mode. And some people, without fully understanding what the immersion model is, confusedly that some system-supplied status bar operations are immersive and also have an immersive status bar name.
For example, there was a QQ group friends asked me, like
# # #面向对象 (Inheritance) # # #
1. Concept of inheritance: inheritance is a relationship between classes and classes, and is a relationship of "is a"
Parent class---> base class Subclass---> Derived class
Note: Inheritance in Java is single-inheritance
2. Advantages of inheritance: Subclasses have all the properties and methods of the parent class (the private adornment is not valid) to implement code reuse
3. Syntax rules: Class Subclass extends Parent class
Cases:
Package Example;public class A
Qi.
2. pu'er tea is a natural health drink with scientific evidence. Hot drinks are comfortable to the stomach and have the best curative effect on constipation and frequent urination. Pu'er tea supplements Qi and Gujing, which also has good effects on men Yang Wei and prostatitis.
3. For women, pu'er tea not only maintains a slim body, but also controls the balance of skin PH to achieve the effect of bodybuilding.
Pu'er tea weight loss Plan II
1. Use pu'er tea to lose weight. The daily concen
Single-Case modeThe singleton pattern is that there is only one instance when the system is running and only a private constructor is provided, which guarantees that an instance of the class cannot be created arbitrarily.First type (a Hungry man mode) Packagecn.smbms.test; Public classSingleton {//define private access Methods PrivateSingleton () {}//Get Instance Private StaticSingleton Singleton =NewSingleton (); //provides a way for outsiders
, the Singleton class can have only one instance.2, the Singleton class must create its own unique instance.3. The Singleton class must provide this instance to all other objects.The advantages of the singleton pattern are:Classes are instantiated only once, saving resources, reducing overhead, and increasing speedSingle-Case Pattern classificationThere are two modes of creating a singleton, one is the A Hungry man mode, the other is the lazy mode, an
B. Hungry Sequencetime limit per test
1 secondMemory limit per test
256 megabytesInput
Standard inputOutput
Standard output
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consistingNIntegers.
A sequenceA1,A2,...,AN, ConsistingOfNIntegers, is Hun
Turn: http://blog.csdn.net/zhengzhb/article/details/7331369
----------------------------------------
Definition:Make sure that a class has only one instance, and instantiate it and provide the instance to the entire system.
Type:Create Class Mode
Class diagram:
Graph knowledge point:
1. class diagrams are divided into three parts: Class names, attributes, and methods.
2. Comments starting with
3. Modifier + indicates public,-Indicates private, # indicates protected, and nothing indicates that
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.