943,929 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2129
  • Java RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Nov 10th, 2008
0

Re: Weird Question

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
> Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why?

We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.
Can you elaborate somewhat on the first example? Do you mean that depending on what the contents are of the XML file, different panels would appear which are created from classes that have their own content... but that the type and size of the panel are always the same? Because I don't see how you could use different sized panels each time, that would mess up the layout. Unless, I suppose, you somehow dynamically figure out how big each panel was and did calculations based on that also. The second example seems to make sense - you have a table and its layout set ahead of time, and based on what Strings are input, that table looks up the classnames (presumably each String represents a classname?) then fills the table with each of those classes, treating a class as a 'column'? That example seems to make sense, because if you wanted to be able to put anything in the table without recompiling, I guess reflection would be the only way to do that.
Last edited by BestJewSinceJC; Nov 10th, 2008 at 11:30 pm.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Nov 10th, 2008
0

Re: Weird Question

Can you elaborate somewhat on the first example? The second example seems to make sense - you have a table and its layout set ahead of time, and based on what Strings are input, that table looks up the classnames (presumably each String represents a classname?) then fills the table with each of those classes, treating a class as a 'column'?
You're sort of right. The classes I was mentioning were generated by crawling throught the DB and writing java code off of the table information. It was really sweet. It didn't use reflection though. It queried the database for metadata.
Reflection is used for calling methods, not class creation. So my DAO (data access object) class would have methods like: getUserId, getCurrentDTTM, etc. And I could call these methods using string literals ("getUserId", "getCurrentDTTM") from the code. Normally you'd use an interface for that kind of work, but since the DAO objects are auto generated, we used reflection
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008
Nov 10th, 2008
0

Re: Weird Question

In the example Ezzaral gave, if he is using a different panel based on whats in the file, he would have to create an Object of the class that represented his panel. So how is it that reflection isn't used to create classes (I'm assuming you meant create objects, not create classes)?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Nov 11th, 2008
0

Re: Weird Question

Quote ...
Do you mean that depending on what the contents are of the XML file, different panels would appear which are created from classes that have their own content... but that the type and size of the panel are always the same? Because I don't see how you could use different sized panels each time, that would mess up the layout.
Layout and/or size are nothing more than attributes that you can put in an xml descriptor like any other property. We place one or more panels in a frame, with whatever attributes are required. The only part that needs reflection at all is the instantiation of a class by name with a specific constructor and the specification of the constructor parameters.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Nov 11th, 2008
0

Re: Weird Question

s.o.s, no offense, but sifting through a ton of material to *maybe* answer my question doesn't sound too appealing. If reflection is indeed useful, there have to be some practical, simple explanations of why this is the case.
It seems as though you missed my entire post. The first two paragraphs of my previous post mention the most widely used implementations of the reflection API. Another use of the reflection API is to implement the Webservice client for SOAP type web services wherein the XML response from the server is converted to an object tree using the schema definitions.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Nov 12th, 2008
0

Re: Weird Question

What I was saying is that I don't understand most of that terminology, so the point alone has no impact. I hope I wasn't rude - I wasn't trying to be.
Last edited by BestJewSinceJC; Nov 12th, 2008 at 12:31 am.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Nov 12th, 2008
0

Re: Weird Question

What I was saying is that I don't understand most of that terminology, so the point alone has no impact. I hope I wasn't rude - I wasn't trying to be.
If you work in an environment similar to mine, you'll have people telling you to "GIYF!" quite a bit XD.

If there is a term you don't understand, you should definitely study it. I find it much easier to learn programming concepts after educating myself with terminology.

Not only that, but by understanding more terminology, you can come up with more meaningful definitions for words in code that you are planning to share with others that may work with you or will be the receiver of an implementation you designed when you hand off the code.

Wikipedia, Google and Dictionary are your ultimate programming friends, to say the least! O_O
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Nov 12th, 2008
0

Re: Weird Question

Point taken, but my point was that a combination of unknown phrases adds a lot of ambiguity which makes it difficult to simply do a google search, combine definitions, then come to an understanding. It makes a lot more sense to explain things with some sort of clarity to begin with. And thats not a slight at s.o.s - he has definitely helped me in the past, and is overall a very helpful guy on this site. I'm just saying that its not out of laziness that I don't look those terms up -- its for the same reason that I wouldn't read a passage out of a French 300 textbook if I only knew basic sentences. It would take hours, maybe months, of work just to understand that passage. But maybe I shouldn't be taking the class in the first place. . or asking questions about reflection and expecting fairly simple answers. Lol. And yes, this analogy sucks. It could be applied in 100000 different ways.
Last edited by BestJewSinceJC; Nov 12th, 2008 at 12:56 am.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Nov 14th, 2008
1

Re: Weird Question

What I was saying is that I don't understand most of that terminology, so the point alone has no impact. I hope I wasn't rude - I wasn't trying to be.
It would be difficult to explain the real use of reflection without throwing in a lot of terminology. Maybe reading this article will help you understand how reflection changes the way we think of object construction/instantiation and how the concept of reflection benefits the real world software development.
Last edited by ~s.o.s~; Nov 14th, 2008 at 10:49 am.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Printing output of an array
Next Thread in Java Forum Timeline: How would you go about coding this?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC