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


Groups > comp.lang.java.programmer > #22126

Re: Design Patterns

Newsgroups comp.lang.java.programmer
Date 2013-02-05 13:10 -0800
References (4 earlier) <singleton-20130205050434@ram.dialup.fu-berlin.de> <ker3s7$cak$1@dont-email.me> <runtime-20130205184718@ram.dialup.fu-berlin.de> <kerifu$pgs$1@dont-email.me> <singleton-20130205192659@ram.dialup.fu-berlin.de>
Message-ID <120b95db-a9a3-4580-9754-46426453280c@googlegroups.com> (permalink)
Subject Re: Design Patterns
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Stefan Ram wrote:
> Eric Sosman writes:
>> A singleton class can be transformed into an uninstantiable
>> class having only static methods.
> 
>   Static methods cannot be passed via reference or used to

Do you mean "via a reference to their owning instance"?

>   implement interfaces. Therefore, there is a need for
>   non-static methods sometimes. But this does not mean a
>   singleton, I am thinking of a POJO first and foremost
>   until someone shows me where a POJO does not suffices,
>   but a singleton is needed.

Most of the time, at least, it suffices to have only one instance of a class where 
otherwise one might be tempted to implement a Singleton.

I have a strong bias toward using instance methods over static methods, in part because 
they can implement an interface method. It does not suffice that the method merely 
doesn't access instance state. It also needs to be "global" by design.

Instance methods can be easier to control in multi-threaded contexts. It's often good to 
have a manager instance that controls the methods so that different units can use them 
independently. 

If you later decide that "singleton" was a mistake, instance methods don't need to be 
refactored.

There's also a circular analysis where type state is maintained in mutable static variables, so one 
creates static methods on the theory that they don't access instance state. 

The risk of mistake with instance methods is lower than with static methods.

So if I have a compelling argument for making a method static, fine, but tie or a close second 
goes to the instance implementation.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Design Patterns dougmmika@gmail.com - 2013-02-02 16:17 -0800
  Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-02 19:39 -0500
    Re: Design Patterns Marcel Müller <news.5.maazl@spamgourmet.org> - 2013-02-03 18:52 +0100
      Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-03 14:23 -0800
      Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 23:57 -0500
        Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-09 11:10 -0800
          Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-09 19:36 -0500
            Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-09 23:44 -0800
              Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-09 23:47 -0800
                Re: Design Patterns "John B. Matthews" <nospam@nospam.invalid> - 2013-02-10 12:28 -0500
              Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-10 13:35 -0500
              Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-10 13:36 -0500
                Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-10 23:12 -0800
          Re: Design Patterns "John B. Matthews" <nospam@nospam.invalid> - 2013-02-09 19:45 -0500
  Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-02 20:17 -0500
  Re: Design Patterns Doug Mika <dougmmika@gmail.com> - 2013-02-02 19:43 -0800
    Re: Design Patterns markspace <markspace@nospam.nospam> - 2013-02-02 20:54 -0800
      Re: Design Patterns Doug Mika <dougmmika@gmail.com> - 2013-02-02 21:11 -0800
        Re: Design Patterns markspace <markspace@nospam.nospam> - 2013-02-03 08:24 -0800
          Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 23:41 -0500
    Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-02 21:57 -0800
  Re: Design Patterns Roedy Green <see_website@mindprod.com.invalid> - 2013-02-03 06:38 -0800
  Re: Design Patterns Joerg Meier <joergmmeier@arcor.de> - 2013-02-04 17:06 +0100
    Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-04 12:38 -0800
    Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-04 21:31 -0500
      Re: Design Patterns Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2013-02-04 21:03 -0800
        Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-04 21:25 -0800
          Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 19:54 -0500
            Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-05 17:51 -0800
              Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 20:54 -0500
        Re: Design Patterns lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-02-05 09:43 +0000
          Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-05 13:03 -0800
            Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 20:09 -0500
          Re: Design Patterns markspace <markspace@nospam.nospam> - 2013-02-05 13:56 -0800
            Re: Design Patterns markspace <markspace@nospam.nospam> - 2013-02-05 14:30 -0800
            Re: Design Patterns Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2013-02-05 14:33 -0800
            Re: Design Patterns lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-02-06 09:03 +0000
          Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 20:07 -0500
      Re: Design Patterns Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-02-05 09:10 -0500
        Re: Design Patterns Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-02-05 13:20 -0500
          Re: Design Patterns Lew <lewbloch@gmail.com> - 2013-02-05 13:10 -0800
          Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 20:11 -0500
      Re: Design Patterns Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-02-05 09:53 -0800
        Re: Design Patterns Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-05 20:17 -0400
        Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 19:50 -0500
      Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-05 20:34 -0500
        Re: Design Patterns Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-02-06 08:40 -0800
          Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 23:38 -0500
    Re: Design Patterns Arne Vajhøj <arne@vajhoej.dk> - 2013-02-04 21:41 -0500

csiph-web