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


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

Re: state design pattern: question: inner or outer class: which is better?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: state design pattern: question: inner or outer class: which is better?
Date Fri, 02 Dec 2011 01:47:47 -0800
Organization Canadian Mind Products
Lines 31
Message-ID <dh7hd799ks0h5f2hh8bg1gr238ndvptfpb@4ax.com> (permalink)
References <4cb57cb9-f87c-4409-9e35-184bdc661f48@l24g2000yqm.googlegroups.com>
Reply-To Roedy Green <see_website@mindprod.com.invalid>
NNTP-Posting-Host Z2l1DcCELS0rATq8NqV4Sw.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
X-Notice Filtered by postfilter v. 0.8.2
X-Newsreader Forte Agent 6.00/32.1186
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10415

Show key headers only | View raw


On Wed, 30 Nov 2011 09:22:01 -0800 (PST), John Goche
<johngoche99@googlemail.com> wrote, quoted or indirectly quoted
someone who said :

>
>Hello,
>
>I am implementing the state design pattern to manage a set of
>sprites in a game. I wonder if anyone could tell me whether it
>is better to implement the state classes as inner classes of the
>object they are a state of, or as outer classes each being passed
>a reference to the sprite object they are being a state for.

There are two main reasons to use inner classes:

1.  When the inner classes need to intimately access the fields of a
particular mother object they are attached to.

2. When you want scope to partly shield the inner classes from the
outside. They treated somewhat as if they were part of the mother
class.

-- 
Roedy Green Canadian Mind Products
http://mindprod.com
For me, the appeal of computer programming is that
even though I am quite a klutz,
I can still produce something, in a sense
perfect, because the computer gives me as many
chances as I please to get it right.
 

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


Thread

state design pattern: question: inner or outer class: which is better? John Goche <johngoche99@googlemail.com> - 2011-11-30 09:22 -0800
  Re: state design pattern: question: inner or outer class: which is better? Lew <lewbloch@gmail.com> - 2011-11-30 11:22 -0800
    Re: state design pattern: question: inner or outer class: which is better? Gene Wirchenko <genew@ocis.net> - 2011-11-30 14:04 -0800
      Re: state design pattern: question: inner or outer class: which is better? Lew <lewbloch@gmail.com> - 2011-11-30 14:28 -0800
        Re: state design pattern: question: inner or outer class: which is better? Gene Wirchenko <genew@ocis.net> - 2011-11-30 15:03 -0800
          Re: state design pattern: question: inner or outer class: which is better? Lew <lewbloch@gmail.com> - 2011-11-30 19:10 -0800
            Re: state design pattern: question: inner or outer class: which is better? Gene Wirchenko <genew@ocis.net> - 2011-11-30 19:23 -0800
  Re: state design pattern: question: inner or outer class: which is better? Roedy Green <see_website@mindprod.com.invalid> - 2011-12-02 01:47 -0800
    Re: state design pattern: question: inner or outer class: which is better? Lew <lewbloch@gmail.com> - 2011-12-02 07:27 -0800
  Re: state design pattern: question: inner or outer class: which is better? Arne Vajhøj <arne@vajhoej.dk> - 2011-12-02 21:32 -0500

csiph-web