Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352200 - Why is the method moveShape final?
Summary: Why is the method moveShape final?
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 0.9.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: Juno M2 theme_round_offs
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-15 07:38 EDT by Michael Wenz CLA
Modified: 2012-06-28 10:40 EDT (History)
1 user (show)

See Also:
michael.wenz: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Wenz CLA 2011-07-15 07:38:50 EDT
In DefaultMoveShapeFeature the method moveShape is final. Does this really make sense, especially because internalMove can be overridden?
Comment 1 Michael Wenz CLA 2011-07-19 04:19:33 EDT
Would like to target for Juno
Comment 2 Tim Kaiser CLA 2011-08-17 04:34:18 EDT
final public void moveShape(IMoveShapeContext context) {
		preMoveShape(context);
		moveAllBendpoints(context);
		internalMove(context);
		postMoveShape(context);
	}

The inner method calls can be overriden. If one does not want to use this structure 
it does not make sense to use the default feature at all. Then one can inherit directly from AbstractMoveShapeFeature and define moveShape completely.
Making this method final blocks misuse of the class. I would keep it as is.
Comment 3 Michael Wenz CLA 2011-08-17 04:44:24 EDT
(In reply to comment #2)
> final public void moveShape(IMoveShapeContext context) {
>         preMoveShape(context);
>         moveAllBendpoints(context);
>         internalMove(context);
>         postMoveShape(context);
>     }
> The inner method calls can be overriden. If one does not want to use this
> structure 
> it does not make sense to use the default feature at all. Then one can inherit
> directly from AbstractMoveShapeFeature and define moveShape completely.
> Making this method final blocks misuse of the class. I would keep it as is.

But there is much more functionality in DefaultMoveShapeFeature that in AbstractMoveShapeFeature and parts of it might be usefull while you would still want to add additional functionality for which you would need to override moveShape (this was the scenario I saw).

What kind of misuse do you see?
Comment 4 Tim Kaiser CLA 2011-08-17 05:25:49 EDT
You can tweak the default move via overriding preMoveShape/postMoveShape/moveAllBendpoints/internalMove.
So the sequence of operations is enforced by the class but still you can override any suboperation. 
If you would allow overriding moveShape as well, the user can forget to move the bendpoints for example etc.
So the class is perfectly extensible (all four methods can be overridden) but also makes it hard to forget to move the bendpoints or do it only after the shape is moved etc
Comment 5 Michael Wenz CLA 2011-08-18 08:40:46 EDT
Ok, agreed that this gives a kind of guidance. But this emerged drom a scenario where a not final moveShape method would have been an easy solution (I had to think a while to recall):

The requirement was to do a check if the move was allowed; the check is expensive (in this case a check if a file has been checked-out). You would not want to do this check in the general pre-execution hook and also not in the canMoveShape method because they are called very often (each time the user moves the mouse). It is also not possible to do this in the preMoveShape, because there you cannot cancel.

The currently used solution (workaround?) was to override moveAllBendpoints, do the check there and throw an exception in case of the condition not beeing fulfilled to end processing the feature further. In case of the condition being true, a super call is done.

A nicer solution would be to override moveShape, do the check there and only do the super call in case the condition is fulfilled.

Another solution I can think of would be the introduction of a return value in preMoveShape with a cancel value and moveShape checking that.

Open to other ideas as well...
Comment 6 Matthias Gorning CLA 2011-08-30 05:00:41 EDT
fixed. simply removed the final modifier.
Comment 7 Michael Wenz CLA 2011-08-30 08:02:58 EDT
Corrected theme and verified change
Comment 8 Michael Wenz CLA 2012-04-11 10:32:01 EDT
Bookkeeping: Set target release
Comment 9 Michael Wenz CLA 2012-06-28 10:40:11 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)