From 00cf2e4ce99f94e488a39923bc3ad6ac12388b9e Mon Sep 17 00:00:00 2001 From: ehilsdal Date: Wed, 27 Aug 2003 20:01:24 +0000 Subject: [PATCH] starting rework for oopsla --- docs/teaching/exercises/index.html | 91 ++++++++++-------------------- 1 file changed, 29 insertions(+), 62 deletions(-) diff --git a/docs/teaching/exercises/index.html b/docs/teaching/exercises/index.html index 4dff3dae0..c69192e46 100644 --- a/docs/teaching/exercises/index.html +++ b/docs/teaching/exercises/index.html @@ -135,6 +135,13 @@ users who bind System.out to a static field to save typing.

b. Mandate setters

+

Problem: Add warnings for assignments outside of setter methods. +

+ +

Tools: set, withincode, +signature void set*(..) +

+

One common coding convention is that no private field should be set outside of setter methods. Write an aspect to warn at compile time when such an illegal assignment expression exists.

@@ -157,53 +164,21 @@ pointcuts. )

Make sure your program still passes the JUnit test tests.Test before continuing, and that you see all of the -following warning messages. You'll notice a LOT of warnings here. -Wait to fix them until the next exercise... +following warning messages. Make sure you get 11 warnings from this. +Wait to fix them until the next exercise.

-
-.\figures\Box.java:17:9: bad field set (warning)
-        _p0 = new Point(x0, y0);
-        ^
-.\figures\Box.java:18:9: bad field set (warning)
-        _p1 = new Point(x0+width, y0);
-        ^
-.\figures\Box.java:19:9: bad field set (warning)
-        _p2 = new Point(x0+width, y0+height);
-        ^
-.\figures\Box.java:20:9: bad field set (warning)
-        _p3 = new Point(x0, y0+height);
-        ^
-.\figures\Group.java:16:23: bad field set (warning)
-        this._members = new ArrayList();
-                      ^
-.\figures\Line.java:15:9: bad field set (warning)
-        _p1 = p1;
-        ^
-.\figures\Line.java:16:9: bad field set (warning)
-        _p2 = p2;
-        ^
-.\figures\Point.java:15:9: bad field set (warning)
-        _x = x;
-        ^
-.\figures\Point.java:16:9: bad field set (warning)
-        _y = y;
-        ^
-.\figures\Point.java:28:9: bad field set (warning)
-        _x += dx;
-        ^
-.\figures\Point.java:29:9: bad field set (warning)
-        _y += dy;
-        ^
-
+

c. Refine setters mandate

+

Problem: Allow assignmnents inside of constructors. +

-

c. Refine setters mandate

+

Tools: signature new(..)

Look at some of the warnings. Notice that a lot of them are from within constructors. Actually, the common coding convention is that -no private field should be set outside of setter methods or -constructors. Modify your answer (in a new file) to signal an +no private field should be set outside of setter methods or +constructors. Modify your answer (in a new file) to signal an actual error at compile time (rather than just a warning) when such an illegal assignment expression exists.

@@ -225,30 +200,15 @@ the following two errors:

2 errors -

(If you see more, go back to 1b; you may be capturing sets to -too many fields.) -

-

Rewrite these two occurrences so as not to violate the convention. Make sure your program still passes the JUnit test tests.Test before continuing.

-

d. Re-refine setters mandate

- -

In part (c), you rewrote the code to fit the convention enforced -by the aspect. It may be that this code doesn't violate the convention -of your mythical organization. Try to instead fix the pointcut so it -doesn't signal an error for these two assignments, and then change -your code back to making the assignments.

- -

Make sure your program still passes the JUnit test -tests.Test before continuing.

- -

Help Yourself by Helping Others

- -

At this point, check the people to your left and right. If -they're stuck somewhere, see if you can help them.

+

d. Congratulatoins

+

You've taken your first steps. At this point, check the people to +your left and right. If they're stuck somewhere, see if you can help +them.

@@ -259,11 +219,18 @@ they're stuck somewhere, see if you can help them.

a. Check a simple precondition

+

Problem: Pass tests.Test2a. +

+ +

Tools: args, before +

+ +

THERE IS AN ANSWER BELOW. LOOK AT IT. TYPE IT IN. +

+

Write an aspect to throw an IllegalArgumentException whenever an attempt is made to set one of Point's -int fields to a value that is either too large (greater -than FigureElement.MAX_VALUE) or too small (less than -FigureElement.MIN_VALUE).

+int fields to a value that is less than zero.

This should make the test case of tests.Test2a pass, which wouldn't without your aspect. So before compiling in the -- 2.39.5