Editing 1188: Bonding

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 34: Line 34:
 
#In the catch block, the aim method of the target of the P instance is called with the Ball instance (now referred to as 'b').
 
#In the catch block, the aim method of the target of the P instance is called with the Ball instance (now referred to as 'b').
 
#The target now executes its own aim method, which is the same code continuing from step 3 except with the current class instance ('this') and its target switched between the parent and the child.
 
#The target now executes its own aim method, which is the same code continuing from step 3 except with the current class instance ('this') and its target switched between the parent and the child.
 +
 +
While compact and suitable for this comic, the code style can be improved if this were a real programming project:
 +
#Good Java code should contain documentation in the form of {{w|Javadoc}} comments.
 +
#It is recommended to organize Java source code into [http://docs.oracle.com/javase/tutorial/java/package/packages.html packages] to make code easier to find and use and to avoid name conflicts.
 +
#The class interface should not expose inner logic and data. For this reason class variables are usually declared as [http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html private] (or protected) and separate public methods (called getters and setters) are created to access the data. Making target private would also require using the setTarget setter method in main to set the parent target to child.
 +
#In most cases constructors should call their superclass constructor first. P descents from Object, which has an empty constructor, so this is not strictly required here.
 +
#The aim method references the class variable target directly. To avoid future name conflicts it is recommended to prefix the reference to target with 'this' or use the getter from #3.
 +
#A <code>try</code> block that does nothing except <code>throw</code> is redundant.  In this comic it is needed to make the code more readable as English sentences, but in programming this pattern should be avoided.
  
 
==Transcript==
 
==Transcript==

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)