CSC/ECE 517 Fall 2011/ch4 4h sv: Difference between revisions
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
__TOC__ | __TOC__ | ||
==Singleton Pattern== | ==Singleton Pattern== | ||
The Singleton design pattern is used to restrict the instantiation of a class to only one instance which is globally available. This is used in situations where a user needs an instance of the class to be available in various parts of the application, being available for logging functionality, communictaion with external systems and database access etc. | The Singleton design pattern is used to restrict the instantiation of a class to only one instance which is globally available. This is used in situations where a user needs an instance of the class to be available in various parts of the application, being available for logging functionality, communictaion with external systems and database access etc. The Singleton pattern is available as a mixin in the Ruby library. Including it in the code makes the new method private and provides an instance method used to create or access the single instance. | ||
Below is an illustration of the implementation of Singleton Design Pattern in Ruby: | Below is an illustration of the implementation of Singleton Design Pattern in Ruby: |
Revision as of 18:23, 16 October 2011
Design Patterns in Ruby
Singleton Pattern
The Singleton design pattern is used to restrict the instantiation of a class to only one instance which is globally available. This is used in situations where a user needs an instance of the class to be available in various parts of the application, being available for logging functionality, communictaion with external systems and database access etc. The Singleton pattern is available as a mixin in the Ruby library. Including it in the code makes the new method private and provides an instance method used to create or access the single instance.
Below is an illustration of the implementation of Singleton Design Pattern in Ruby: