Weird Question

Thread Solved

Join Date: Sep 2008
Posts: 1,580
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 199
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Weird Question

 
0
  #21
Nov 10th, 2008
Originally Posted by Ezzaral View Post
> 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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 19
Reputation: bionicseraph is an unknown quantity at this point 
Solved Threads: 6
bionicseraph bionicseraph is offline Offline
Newbie Poster

Re: Weird Question

 
0
  #22
Nov 10th, 2008
Originally Posted by BestJewSinceJC View Post
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,580
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 199
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Weird Question

 
0
  #23
Nov 10th, 2008
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)?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,454
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Weird Question

 
0
  #24
Nov 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,617
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Weird Question

 
0
  #25
Nov 11th, 2008
Originally Posted by BestJewSinceJC View Post
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,580
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 199
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Weird Question

 
0
  #26
Nov 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Weird Question

 
0
  #27
Nov 12th, 2008
Originally Posted by BestJewSinceJC View Post
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,580
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 199
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Weird Question

 
0
  #28
Nov 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,617
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Weird Question

 
1
  #29
Nov 14th, 2008
Originally Posted by BestJewSinceJC View Post
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC