On 2014-06-19 15:52, Steven D'Aprano wrote:
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.
You've got me thinking but I'm still at a loss as to what questions need
asked!
The only applicability that fits in with anything I've experienced has
to do with the necessity of globals to represent command line parameters
which must be read at the outset and then be available to direct program
execution.
Thanks for the "tip."
alex
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor