refactoring : Java Glossary

logorefactoring
Cleaning up code, perhaps by moving a field from one class to another, pushing some code up or down a hierarchy. Most often it is the process of splitting out repetitive code to turn it into its own separate method. An automated tool such as a SCIDs to help you do might work like this:
  1. I have a method which has some code that I would like to pull out into its own method.
  2. I highlight the offending code.
  3. I select Extract Method from a popup menu
  4. The Refactoring Browser asks me to name the method and automatically creates it and inserts the highlighted code.
  5. In the current method, the highlighted code is replace by an invocation to the newly created method.

Ideally, in a perfectly written computer program, with a perfectly designed computer language, with a perfect SCID/ IDE, it should be possible to change any line/element of the program in isolation without having to make any supporting changes elsewhere. The program should still function in a reasonable way. For example, you should be able to change the allowable bounds on a field variable in one line of code (which might result in it internally being promoted from int to long), without having to manually adjust any other code. The basic principle is you should have to tell a computer any one fact, or decision in only one place. For example, you should have to tell a program which colour scheme to use in precisely one and only one place, and by “one place” I mean one line of code. Real life computer languages and IDE (Integrated Development Environment)s put up huge roadblocks to getting anywhere close to perfection.

Java is a very refactoring-friendly language. You can change the type of a variable, add or remove a parameter to a method, Change something from static to instance or the reverse. Move code around. Split code up. Rename. You can do these things with a refactoring tool such as the one in IntelliJ, but even if it or you screw up or fail to complete the changes, as soon as you compile, the error mesages will warn you of other things you must change to be consistent. Pretty much, when you get a clean compile, your code will work.

IntelliJ

I use Jetbrains IntelliJ IDEA as my IDE, which supports many canned refactorings with a few mouseclicks. Some of the most useful are: It is a whole new way of programming. By letting the computer handle the details of the transformations, you can rapidly rearrange code without breaking it. You tend then to hold yourself to an ever higher standard. It is a step on the road to a SCID (Source Code In Database) where you don’t transform its deep structure to view it in alternate ways.

Algebra

If you recall your grade 7 algebra, you learned to refactor. You learned to convert 7a + 7b to 7(a + b). You look for commonality then split it out so that it appears only once. This is the same thing you do to refactor Java. You look for common code. Then you split it out so there is no repetition of it. You can have two classes implement a common interface, or one class inherit from another or two classes inherit from a common base class, possibly abstract. You write the common code in using only the fields and methods of the common interface or class.

Books

book cover recommend book⇒Refactoring: Improving the Design of Existing Code
by:Martin Fowler, Kent Beck [Contributor], John Brant [Contributor], William Opdyke, Don Roberts 978-0-201-48567-7hardcover
 (born: 1963 age: 48) B000OZ0N4Ykindle
publisher:Addison-Wesley
published:1999-07-08
Discusses how reorganising code into standard patterns makes it easier to maintain. Highly recommended. Practical before and after examples of cleaning up stinking code.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag iberlibro.com amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Powells American flag
American flag download O’Reilly Safari download Sony e-books American flag
Kobo UN flag
Greyed out stores probably do not have the item in stock
book cover recommend book⇒Code Complete: A Practical Handbook of Software Construction
by:Steve McConnell 978-1-55615-484-3paperback
publisher:Microsoft 978-0-7356-3697-2ebook
published:1993-05-14
Gives lots of practical advice on optimising. He talks mostly about C with examples in Fortran, Pascal, Basic and Ada. He doesn’t talk about Java. It didn’t exist when the book was written.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag iberlibro.com amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Powells American flag
American flag O’Reilly Safari Sony e-books American flag
download Kobo UN flag
Greyed out stores probably do not have the item in stock
book cover recommend book⇒Refactoring Workbook
by:William C. Wake 978-0-321-10929-3paperback
publisher:Addison-Wesley
published:2003-09-06
has exercises and real world examples. An emminently practical book.
Australian flag abe books anz abe books.co.uk UK flag
German flag abe books.de amazon.co.uk UK flag
German flag amazon.de abe books.ca Canadian flag
Spanish flag iberlibro.com amazon.ca Canadian flag
Spanish flag amazon.es Chapters Indigo Canadian flag
French flag abe books.fr abe books.com American flag
French flag amazon.fr amazon.com American flag
Italian flag abe books.it Barnes & Noble American flag
Italian flag amazon.it Powells American flag
American flag download O’Reilly Safari Sony e-books American flag
Kobo UN flag
Greyed out stores probably do not have the item in stock

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/refactoring.html J:\mindprod\jgloss\refactoring.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.214]
You are visitor number 56,057.