Jump to content

  • Log In with Google      Sign In   
  • Create Account


Java Technique: Using static inner class for debug purposes, then bring it out as a independent class for release


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 568

Like
0Likes
Like

Posted 22 November 2012 - 12:06 PM

This is merely a discussion of a technique I came up with, and I wanted to talk about it before I really take it far.

Suppose you wanted to create a new object. Instead of having to create a new Java file, we can just create a static class inside of an outer class, and treat the static class as a new class. For example, I have a Foo class, and I need a new Object. I can just go ahead and add a static class Bar inside Foo, like this:

[source lang="java"]//Outer, regular, independent classpublic class Foo { //Inner, temporary class used for debugging. static class Bar { //... }}[/source]
I could then treat the Bar class as a independent class for Foo. A basic rundown looks like this:

[source lang="java"]public class Foo { //We treat this as a class of its own. private Bar bar; //WRONG, we don't want to do this. We do not try to link it to Foo: //private Foo.Bar bar static class Bar { //Basic rundown on making Bar useful. private boolean code; //Setter public void setCode(boolean value){ code = value; } //Getter public boolean getCode(){ return code; } } //Initialization public Foo(){ bar = new Bar(); } //How we obtain the Bar object. Again, we don't link it to Foo. public Bar getBar(){ return bar; } //WRONG, we don't want to do this: //public Foo.Bar getBar() {...}}[/source]

And this how we execute Bar as a demonstration:

[source lang="java"]public static void main(String[] args){ Foo foo = new Foo(); foo.getBar().setCode(true); boolean test = foo.getBar().getCode(); //...}[/source]

Thus, I have shown you the technique. From here, we can continue to test and debug, and when the Bar object is useful enough, we can then bring it out as a independent class (and giving it its own Java source file). A few questions:
  • Is this technique useful enough?
  • Would you use it? Why?
  • How would you use it?


Sponsor:

#2 Slavik81   Members   -  Reputation: 360

Like
0Likes
Like

Posted 22 November 2012 - 12:14 PM

Why is it difficult to create a completely new, independent class in Java? Personally, I think you'd be better off making it simpler to create new classes than developing techniques to work around how troublesome it is.

#3 rip-off   Moderators   -  Reputation: 8119

Like
0Likes
Like

Posted 22 November 2012 - 12:45 PM

I don't really understand how this is related to debugging. It sounds like you use this technique to prototype designs quickly.

#4 tom_mai78101   Members   -  Reputation: 568

Like
0Likes
Like

Posted 22 November 2012 - 11:39 PM

I don't really understand how this is related to debugging. It sounds like you use this technique to prototype designs quickly.


Is that how I should describe this technique? Yes, I believe, I just don't know how to describe it prior to your post.

#5 Bubsy   Members   -  Reputation: 407

Like
0Likes
Like

Posted 23 November 2012 - 06:42 AM

I can understand not using, for debug purposes, methods (as the JVM debuggers code hotswap facilities is unable to change class structure). But I really don't see how this technique make it easier to debug.

Just create the new class on its own source code, if the class turn out to be worthless, delete it ;) my 2 cents




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS