Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32184
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to access properties of a class from another class? |
| Date | 2015-07-28 16:59 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mp8qk9$49v$1@dont-email.me> (permalink) |
| References | <mp8m3g$dk2$1@speranza.aioe.org> |
On 07/28/2015 03:45 PM, Xue Feng wrote: > Hi, > > Beg your pardon for this silly question.I am familiar with the concept > of encapsulation indeed. However, for some problems, I think there must > be better solutions. > > My question comes from a feature of Netbeans which is well-known for its > wonderful GUI design facilities. However, for all GUI components, > Netbeans likes to cram them into a single source file of the main frame. > A direct result for this is all code pertain to definition of GUI > component objects and event handling are concentrated in a source file, > and it meants to flate rapidly. For large-scale projects, this is not a > good idea.(I have only little experience with Netbeans for two weeks. > There mybe other options I don't know. Tell me please.) > > To practice MVC schema, it is necessary to design separate control class > and view class. The reason you use a GUI builder is to free yourself from having to deal with the architecture of the GUI model and concentrate on your problem domain. Let it do its job. > Both of them have occasions to interact with GUI > components. However, all of components are defined in the main frame > class as private members. Therefore, control class and view class need > to access these components encapsulated in the main frame class. I think > there mybe some ways to achieve the goal as follows: > > (1) Define control class and veiw class as inner class of the main frame > class. But, this practice will result in a huge souce file obviously. > (2) Define components as public members. However, it seems that Netbeans > does not allow this way. > (3) Define many 'get' methods for the main frame class, and invoke them > from control class and view class to get references of component > needed. This is an ordinary pratice, but somewhat tedious. Moreover, it > also lacks flexibility especially when the GUI design changes frequently. > (4) Take some language construct such as friend class from C++. I don't > konw whether Java has this kind of construct. > (5) Is there any way to dynamically generate an object at runtime in > terms of the main frame class as template? This object wraps up all > components' reference as its public member. Then, pass the object to > control object and view object. Maybe reflection can help, but I am not > sure about it. > > For the above specific situation, I wonder whether there are ways to > circument encasulation to make programming more convenient and flexibiable. Yes, ditch the GUI builder and build it all yourself.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to access properties of a class from another class? Xue Feng <xf.lotus@yahoo.com> - 2015-07-29 03:45 +0800
Re: How to access properties of a class from another class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-28 16:58 -0400
Re: How to access properties of a class from another class? Jeff Higgins <jeff@invalid.invalid> - 2015-07-28 16:59 -0400
Re: How to access properties of a class from another class? Nigel Wade <nmw@ion.le.ac.uk> - 2015-07-29 15:24 +0100
Re: How to access properties of a class from another class? Xue Feng <xf.lotus@yahoo.com> - 2015-08-01 16:10 +0800
csiph-web