Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.perl.misc > #4793

Re: getting hash reference from a package

From Rainer Weikusat <rweikusat@mssgmbh.com>
Newsgroups comp.lang.perl.misc
Subject Re: getting hash reference from a package
Date 2012-03-18 22:12 +0000
Message-ID <8739958snp.fsf@sapphire.mobileactivedefense.com> (permalink)
References <jjnsjo$57f$1@dont-email.me> <NaY7r.589637$lb1.44216@news.usenetserver.com> <QuudnQV4rJn4Tv3SnZ2dnUVZ_vSdnZ2d@posted.hiwaay2> <871uovcan7.fsf@sapphire.mobileactivedefense.com> <1tOdnQun9cWw6f7SnZ2dnUVZ_vCdnZ2d@posted.hiwaay2>

Show all headers | View raw


gbacon@hiwaay.net (Greg Bacon) writes:
> Rainer Weikusat wrote
> : A singleton is the Java programmer's workaround for the fact that
> : Java requires everything to be an instance of some class, that is,
> : a general blueprint for construction objects of certain kinds, but
> : that many real-world problems are easier dealt with by systems
> : constructed of stateful modules ('subsystems') providing some kind of
> : identifiable, useful functionality for solving a part of the original
> : problem (that's similar to complex real machines which are also
> : composed of cooperating 'sub-machines' dealing with 'subtasks' of the
> : problem supposed to be solved). [...]
>
> The singleton pattern[1] isn't specific to Java even though denizens
> of that language do tend to fetishize it. Java doesn't require
> everything to be an instance of a class, the counterexample aside
> from basic types being static methods. Even so, say we have the
> module-qua-class
>
>   public class MyModule {
>     static int calls_ = 0;
>
>     public static void SayHi() {
>       ++calls_;
>       System.out.println("Hello!");
>     }
>
>     public static void SayBye() {
>       ++calls_;
>       System.out.println("Good-bye!");
>     }
>
>     public static int Calls() {
>       return calls_;
>     }
>   }
>
> MyModule fits your description above, but it is not a singleton.
> The name of the pattern derives from the constraint that a system
> may have at most a single instance of such a class. You might claim
> that a bag of static methods meets the definition in its vacuous
> sense, but such usage robs the term of its meaning.

Since there's no class instance in the example above, it obviously
doesn't make sense to call it 'a singleton'. OTOH, both serve the
same purpose: Express the concept of 'a subsystem', that is, some set
of state variables shared by some set of 'public' interface routines
intended to solve a subproblem of the problem the program containing
this code is supposed to solve, in Java. For the purpose of this
discussion, ie, the 'global variable dressed in fancy clothes' issue,
both have the same properties and there's actually nothing wrong with
that: A subsystem is isomorph to a single instance of some class
(that's exploited by the so-called 'singleton pattern') and this
implies that any single object is nothing but 'a fancily dressed
global variable'. 

> Rather than imposing the single-instance constraint, creating a
> singleton as a shortcut to bypass threading the instance through
> the call graph is a frustratingly common practice.

Hmm ... what is this supposed to mean?

Back to comp.lang.perl.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

getting hash reference from a package Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-13 11:28 -0500
  Re: getting hash reference from a package Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-13 11:44 -0500
    Re: getting hash reference from a package tmcd@panix.com (Tim McDaniel) - 2012-03-13 17:56 +0000
      Re: getting hash reference from a package Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-13 13:07 -0500
        Re: getting hash reference from a package Jack <goodcall1@hotmail.com> - 2012-03-14 01:57 -0600
          Re: getting hash reference from a package Martijn Lievaart <m@rtij.nl.invlalid> - 2012-03-14 12:06 +0100
            Re: getting hash reference from a package tmcd@panix.com (Tim McDaniel) - 2012-03-14 15:37 +0000
              Re: getting hash reference from a package Ben Morrow <ben@morrow.me.uk> - 2012-03-14 17:54 +0000
          Re: getting hash reference from a package Ben Morrow <ben@morrow.me.uk> - 2012-03-14 14:27 +0000
            Re: getting hash reference from a package Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-14 18:28 +0000
              Re: getting hash reference from a package Ben Morrow <ben@morrow.me.uk> - 2012-03-14 21:08 +0000
                Re: getting hash reference from a package Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-14 21:23 +0000
          Re: getting hash reference from a package gbacon@hiwaay.net (Greg Bacon) - 2012-03-14 12:20 -0500
            Re: getting hash reference from a package Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-14 18:14 +0000
              Re: getting hash reference from a package gbacon@hiwaay.net (Greg Bacon) - 2012-03-16 12:11 -0500
                Re: getting hash reference from a package Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-18 22:12 +0000
                Re: getting hash reference from a package gbacon@hiwaay.net (Greg Bacon) - 2012-03-20 10:28 -0500
          Re: getting hash reference from a package Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-14 20:52 +0000

csiph-web