assertEquals(___, editor.fetch(1));
A. Given the interface provided, what string would you expect to use in place of the ___?
"a"
B. Based on the variable name (firstParendPosition), what string might you like to use instead? Of what use would this be?
"("
It is sometimes useful to have positions that remember where they are, even if text is inserted in front of them. For example, a programming editor might track the position of each method declaration. C. The crux of the problem is the use of int as a position index. Suggest an alternative approach. Instead of handing out dead integers, hand out Position objects, but let the editor own them. When text changes, the editor updates the Positions. The holders of the objects aren't aware of that; they just know that they can get one or hand it back to move to a prior position. D. Relate your solution to the Memento design pattern. Memento uses an opaque object; in this case, the editor may know what's inside, but clients definitely don't. The client can't manipulate the Memento pattern directly, but must hand it back to the main object to use it. |