[Tutor] Tips

Steven D'Aprano steve at pearwood.info
Fri Jun 20 00:52:57 CEST 2014


On Thu, Jun 19, 2014 at 11:10:26AM -0700, Alex Kleider wrote:

> The idea of a singleton class is new to me as is this comparison of 
> class vs module.
> Can anyone suggest a place to turn for more discussion of the topic?
> thks, alexK

"Singleton" is one of the classic "design patterns", although these days 
people are equally divided on whether it's a design pattern or 
anti-pattern.

The idea of design patterns is that they are a standard way of solving a 
certain type of problem. For example, in the real world, there are 
various problems which have a certain factor in common:

    Example problems:
    - Painting a mural on the ceiling. Building a house. Replacing
      a broken window on the 2nd story. Making a tree house.

    Class of problem:
    - There is work needed at a height well above what you can 
      reach from the ground.

    General solution:
    - Use scaffolding to raise the height at which you can
      comfortably work.

So "scaffolding" is the design pattern. Actual scaffolds may be made 
from many different materials (steel, timber, bamboo) and in many 
different shapes and sizes, but they're all scaffolds. Rather than there 
being a "one size fits all" solution for all problems, instead there is 
a general solution that you customize for the specific problem. The size 
and shape of the scaffolding needed to replace a broken window will be 
different than that needed to build a house.

Design patterns for software are like scaffolds: a design pattern is not 
a language feature or function you can call, but a general technique to 
be used to solve a class of problems.

https://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29

Explicit use of design patterns is very, very big in the Java and 
Dot Net worlds, less so in other programming languages.


To learn more, Duck Duck Go is your friend:

https://duckduckgo.com/html/?q=singleton+design+pattern
https://duckduckgo.com/html/?q=singleton+anti-pattern

If you still prefer Google:

https://www.google.com/search?q=singleton+design+pattern

or feel free to ask questions here.



-- 
Steven


More information about the Tutor mailing list