Re: Java and Objective-C
Re: Java and Objective-C
- Subject: Re: Java and Objective-C
- From: Denis Bohm <email@hidden>
- Date: Sat, 7 Jun 2008 13:30:02 -0700
On Jun 7, 2008, at 12:38 PM, Bill Bumgarner wrote:
On Jun 7, 2008, at 12:01 PM, Felipe Monteiro de Carvalho wrote:
On Sat, Jun 7, 2008 at 11:38 AM, Jose Raul Capablanca <email@hidden
> wrote:
With the exception of the id and SEL types,
categories, and the fact that you can send messages to nil, I
can't think of
anything in Obj-C that isn't done better in Java,
Here is one: Integration with other languages
Java's integration with other languages (as using Java libraries in
other languages) is about one of the worse I've ever seen. It
basically makes any Java library accessible to only Java.
And a second one: Performance
This comes up time and time again -- Why did Apple choose Objective-
C vs. Language X?
That is off topic for cocoa-dev and, thus, not a useful direction
for taking this particular conversation.
I believe, however, that there is an on-topic direction within which
to frame this particular discussion that will be helpful to folks
new to the platform and educational to those that may not know, say,
Java.
Specifically -- a programming question. Easily framed.
How would you implement NSUndoManager in Java?
I'm very new to Objective-C and have used Java so I'll take a shot at
that. First of all there are many ways to implement an undo / redo
manager in Java. I'll try to keep this close to how it appears to me
that the Objective-C interface works, which is just my understanding
from a quick read of one of the help pages:
http://developer.apple.com/documentation/Cocoa/Conceptual/UndoArchitecture/Tasks/RegisteringUndo.html#/
/apple_ref/doc/uid/20000206-BABICFDE
The Objective-C example on that page is:
- (void)setGridVisible:(NSNumber *)flag {
BOOL flagValue = [flag boolValue];
if (gvFlags.showGrid != flagValue) {
NSNumber *currentValue = [NSNumber
numberWithBool:gvFlags.showGrid];
gvFlags.showGrid = flagValue;
if (flagValue)
[graphicView resetGUP];
[graphicView cache:[graphicView bounds]];
[undoManager registerUndoWithTarget:self
selector:@selector(setGridVisible:)
object:currentValue];
[undoManager setActionName:GRID_OP];
}
Something similar in Java could be done as:
void setGridVisible(boolean flagValue) {
if (gvFlags.showGrid != flagValue) {
boolean currentValue = gvFlags.showGrid;
gvFlags.showGrid = flagValue;
if (flagValue) {
graphicView.resetGUP();
graphicView.cache(graphicView.bounds());
undoManager.registerUndoWithTarget(this, "setGridVisible",
currentValue);
undoManager.setActionName(GRID_OP);
}
Where the methods in the Java UndoManager could be implemented
something like:
public void registerUndoWithTarget(Object target, Method method,
Object... args)
public void registerUndoWithTarget(Object target, String methodName,
Object... args) {
Method[] methods = target.getClass().getDeclaredMethods();
Method method = getBestMatch(target.getClass(),
getTypesOf(args)); //
...
}
protected Method getBestMatch(Class targetClass, Class[] argClasses) {
Method[] methods = targetClass.getDeclaredMethods();
...
}
The Objective-C and Java versions of the user code look pretty
similar. What aspects of the Objective-C undo manager am I missing?
Denis
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden