Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10370
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: state design pattern: question: inner or outer class: which is better? |
| Date | 2011-11-30 11:22 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <4652620.1006.1322680967944.JavaMail.geo-discussion-forums@prfi36> (permalink) |
| References | <4cb57cb9-f87c-4409-9e35-184bdc661f48@l24g2000yqm.googlegroups.com> |
John Goche wrote: > 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. It all depends. What do you mean by "better"? What is the use case for the sprite type? If the sprite state depends on the outer class's state, an inner class can be a convenient shortcut. As with non-inner nested classes, if the type is needed by any other class and its semantics are not tightly bound to those of the proposed outer class, a standalone class is probably more appropriate. If the semantics are tightly bound to the proposed outer class, and the sprite state does not depend on the outer class instance's state, then a nested class might be appropriate. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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