Reprinted please indicate the source: http://blog.csdn.net/guolin_blog/article/details/8868758
This is a copy version of Java Design Pattern dialysis, which is specially provided for Ruby lovers. If you are not familiar with Ruby syntax, please refer:
Java Design Pattern Analysis-singleton)
When writing software, you often need to use the log printing function,
the basis of the original code).
Require ' singleton '
class Logger
include singleton
#Omit the remaining code End
First, introduce the SINGLETON.RB file from the system configuration path, and then introduce the Singleton module in the Logger class. OK, it's all finished!
"What?! "You simply don't believe your eyes
Demonstrate Ruby's six characteristics that are easy to be misunderstood with actual code. The Code demonstrates ruby misunderstanding.
Introduction: if you are a C ++ developer, you need to use Ruby to quickly execute some prototype designs. When you pick up a Ruby reference book (such as Pickaxe) or browse a Ruby web
PHP Implementation Singleton () Singleton pattern example, singleton instance
In this paper, the method of implementing Singleton () Singleton mode in PHP is described. Share to everyone for your reference. The implementation method is as follows:
The common.php file is as
In the daily work, there are many objects, we only need one. For example: thread pool, cache, registry, etc. If multiple instances are produced, many problems can result, such as abnormal program behavior, excessive resource usage, and so on. This requires controlling the construction of an object so that it can produce only one object. This is the design pattern to be talked about-Singleton (singleton).Def
Document directory
Test Singleton Mode
Multi-thread considerations
Synchronization
A Method for Improving Performance
Double lock check
Implementation of an improved thread-safe Singleton Mode
Test Singleton Mode
Next, I use JUnit corresponding to log4j to test the singleton class, which runs through the rest o
other commands. The command object is only responsible for executing its own tasks or commands, in addition, the command mode can remember the previous operation, so many text editors usually use the command mode for Undo/Redo operations.
Articles you may be interested in:
Example Analysis of Observer Pattern in Ruby programming in Design Pattern
Instance parsing Implementation of observer mode in Ruby
the Combination Mode and Its Application in Ruby Design Mode Programming
The template method in the design mode applies two examples in Ruby.
Example parsing: Use of Strategy Mode in Ruby Design Mode Programming
The example explains how Ruby uses the decorator mode in the design mode.
Example of using Builder mode
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 itsel
Document directory
Use the Registry
Use reflection
Encapsulate the Registry
Classloaders
Serialization
Singleton mode conclusion
Use the Registry
You can use a singleton registry:
In running period refers to order EXAMPLE Class
Prevents instances that generate multiple Singleton subclass classesIn the singleton
1. Why Ruby?
Why do many Java developers focus on Ruby? Ruby is a general-purpose scripting language created in Japan 10 years ago. It is a pure object-oriented language. Unlike Java, everything in ruby is an object. Ruby syntax mainly comes from smalltalk, Python and Ada.
close @ file. another dynamic method for implementing the decoration mode in colse end ruby: modifies the instance method of an object. Therefore, a time stamp is added to the out1.txtfile without affecting the time stamp of the sw2,out2.txt object. Sw1 = SimpleWriter. new ("out1.txt") class
Articles you may be interested in:
Detailed description of the structure of the Combination Mode and Its Application in
Singleton mode is very simple, that is, in the constructor and add a constructor, access permissions are private, this pattern is simple, but the risk of simple, risk? What risk? In a B/s project, each HttpRequest request to the Java EE container creates a thread, and each thread creates the same singleton object./*** I ' m glad to share my knowledge.* China's history is generally a dynasty an emperor, t
replace it with the specific operation factory, namely the addition factory, the subtraction factory, the multiplication factory and the Division factory.
Articles you may be interested in:
Detailed description of the structure of the Combination Mode and Its Application in Ruby Design Mode Programming
The template method in the design mode applies two examples in Ruby.
Example parsing: Use of Strategy
end 6 7 module N 8 def method 9 puts "this is method in module N"10 end11 end12 13 class C14 include M15 include N16 end17 18 C.new.method19 p C.ancestors
Output result
This is method in Module N[C, N, M, object, kernel, basicobject]
Class C contains two modules, m, n, m, and N, which have the method. So which one to call? If the method defined in ruby is in the same class, it overwrites the old method. Similarly, if Modul
1. Definition of a singleton patternA singleton pattern (Singleton pattern) is a simpler pattern.The original definition is as follows: Ensure a class has only one instance, and provide a global point of access to it. That is, ensure that there is only one instance, and instantiate it yourself and provide this instance to the system as a whole. A generic class fo
end def contains s1.20.s2.20.s3.20.n1.20.r1.20.endf1 = Fund. newf1.buyf1. bytes
Benefit: You don't need to know about all kinds of stocks, you just need to buy and sell funds.
Articles you may be interested in:
Detailed description of the structure of the Combination Mode and Its Application in Ruby Design Mode Programming
The template method in the design mode applies two examples in Ruby.
Example par
I have recently considered a lot of metaprogramming (metaprogramming) issues and would like to see more examples and explanations of this technology. For better or worse, Metaprogramming has entered the Ruby community and is a standard way to accomplish various tasks and simplify code. Since I can't find this kind of resources, I'm going to start writing some general Ruby technology articles. These may be u
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.