Skip navigation.
 
mlRe: Java vs. Objective-C for Cocoa
FROM : Keith Ray
DATE : Sun Apr 24 18:00:21 2005

Refactoring is about behavior-preserving changes to the structure of
classes and methods. (Obviously only the behavior your interested
in... refactorings may increase or decrease the number of method
calls, which can increase or decrease the stack depth and timings.
Usually such things are not that the behavior of interest.)

You get the structure of classes and methods by doing the same kind of
parsing that the compiler does *or* by using run-time reflection. All
refactoring tools that I know of, even the Smalltalk ones, use parsing
primarily... but I could be wrong.

In any parsing-a-language situation, the lowest level involves lexing,
which can be done by regular expressions. The rest of parsing builds
on top of that.

The problem with Objective-c is that we have the preprocessor... this
is also a problem with C++, though C++ templates and complexity of
that language have hampered creation of refactoring tools. In spite of
this problem, some C++ refactoring tools are coming out.

On the other hand, if the preprocessor isn't abused, Objective-C is a
simple enough language to be parsed without writing a full compiler,
and therefore refactoring tools * could * be written if motivated
people wanted to.

Here's a few refactorings that would be useful. (See
http://www.refactoring.com/catalog/index.html for a "complete" list.)

"Collapse Heirarchy" - choose this menu item in your IDE, get prompted
to select two or more classes, the tool collapses all the selected
classes into one base class. It finds all references to the
now-extinct classes and changes them to refer to the base class.
Whatever "merges" that can't be done reliably via software are left to
be done by the programmer.
<http://www.refactoring.com/catalog/collapseHierarchy.html>

"Extract Class" - select one or more member variables, and/or one or
more methods, choose this menu item in your IDE, and get prompted for
a new class name. This tool creates a new class containing those
variables and/or methods, and in the old class, replaces the
variable/methods with references to the new class.
<http://www.refactoring.com/catalog/extractClass.html>

"Extract Interface" - to use Objective-C terminology, that would be
"Extract Protocol"...
<http://www.refactoring.com/catalog/extractInterface.html>

"Extract Method" - this is the most commonly-used refactoring,
especially with legacy code, which almost always has too-big methods.
<http://www.refactoring.com/catalog/extractMethod.html>

"Inline Method" - the opposite of Extract Method. Sometimes you need
to inline several methods in one, and then extract methods in a
different way, to put the where code belongs. 
<http://www.refactoring.com/catalog/inlineMethod.html>

"Extract Superclass" - this moves common features from two or more
classes into a common base class.
<http://www.refactoring.com/catalog/extractSuperclass.html>

"Pull Up" Method/Variable and "Push Down" Method/Variable... moving
things from subclass to parent-class and vice-versa.

"Replace Inheritance with Delegation"
<http://www.refactoring.com/catalog/replaceInheritanceWithDelegation.html>

"Replace Method with Method Object"
<http://www.refactoring.com/catalog/replaceMethodWithMethodObject.html>

"Replace Temp with Query"
<http://www.refactoring.com/catalog/replaceTempWithQuery.html>

---
C. Keith Ray
<http://homepage.mac.com/keithray/blog/index.html>
<http://homepage.mac.com/keithray/xpminifaq.html>
<http://homepage.mac.com/keithray/resume2.html>

Related mailsAuthorDate
mlJava vs. Objective-C for Cocoa Zacharias J. Beckm… Apr 22, 20:14
mlRe: Java vs. Objective-C for Cocoa Scott Stevenson Apr 22, 21:49
mlRe: Java vs. Objective-C for Cocoa Marianne Kern Apr 23, 00:04
mlRe: Java vs. Objective-C for Cocoa Zacharias J. Beckm… Apr 23, 00:16
mlRe: Java vs. Objective-C for Cocoa Don Yacktman Apr 23, 01:53
mlRe: Java vs. Objective-C for Cocoa Rick Kitts Apr 23, 04:44
mlRe: Java vs. Objective-C for Cocoa John Stiles Apr 23, 06:46
mlRe: Java vs. Objective-C for Cocoa Zacharias J. Beckm… Apr 23, 19:29
mlRe: Java vs. Objective-C for Cocoa Rick Kitts Apr 23, 20:15
mlCocoa Apps on Windows was: Re: Java vs. Objective-C for Cocoa Lars Sonchocky-Hel… Apr 23, 21:02
mlRe: Java vs. Objective-C for Cocoa Ondra Cada Apr 23, 22:29
mlRe: Java vs. Objective-C for Cocoa Thomas Davie Apr 23, 22:43
mlRe: Java vs. Objective-C for Cocoa Rick Kitts Apr 23, 23:30
mlRe: Java vs. Objective-C for Cocoa Ondra Cada Apr 23, 23:41
mlRe: Java vs. Objective-C for Cocoa Jonathon Mah Apr 23, 23:53
mlRe: Java vs. Objective-C for Cocoa Thomas Davie Apr 23, 23:58
mlRe: Java vs. Objective-C for Cocoa Marcel Weiher Apr 24, 00:13
mlRe: Java vs. Objective-C for Cocoa Ondra Cada Apr 24, 00:30
mlRe: Java vs. Objective-C for Cocoa Ondra Cada Apr 24, 00:38
mlRe: Java vs. Objective-C for Cocoa Keith Ray Apr 24, 05:08
mlRe: Java vs. Objective-C for Cocoa Zacharias J. Beckm… Apr 24, 06:18
mlRe: Java vs. Objective-C for Cocoa Zacharias J. Beckm… Apr 24, 06:38
mlRe: Java vs. Objective-C for Cocoa Todd Blanchard Apr 24, 08:36
mlRe: Java vs. Objective-C for Cocoa Marcel Weiher Apr 24, 10:41
mlRe: Java vs. Objective-C for Cocoa Ondra Cada Apr 24, 11:50
mlRe: Java vs. Objective-C for Cocoa Thomas Davie Apr 24, 12:24
mlRe: Java vs. Objective-C for Cocoa Marcel Weiher Apr 24, 13:04
mlRe: Java vs. Objective-C for Cocoa Ondra Cada Apr 24, 15:55
mlRe: Java vs. Objective-C for Cocoa Thomas Davie Apr 24, 16:43
mlRe: Java vs. Objective-C for Cocoa Todd Blanchard Apr 24, 17:54
mlRe: Java vs. Objective-C for Cocoa Keith Ray Apr 24, 18:00
mlRe: Java vs. Objective-C for Cocoa Jonathon Mah Apr 25, 01:39
mlRe: Java vs. Objective-C for Cocoa Roarke Lynch Apr 25, 04:58
mlRe: Java vs. Objective-C for Cocoa Scott Ellsworth Apr 25, 20:23