User Tools

Site Tools


invariant:ex2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
invariant:ex2 [2007/02/25 17:48] bdefraininvariant:ex2 [2021/02/05 13:53] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Invariants: Mandate setters ======+[[invariant:intro|Intro]] 
 +[[invariant:ex1|Ex1]] 
 +[[invariant:ex2|Ex2]] 
 +[[invariant:ex3|Ex3]] 
 +[[invariant:ex4|Ex4]] 
 +[[invariant:ex5|Ex5]]====== Invariants: Mandate setters ======
  
 **Task:** Signal a warning for assignments to private fields outside of setter methods. **Task:** Signal a warning for assignments to private fields outside of setter methods.
Line 16: Line 21:
 **Tools:** The ''set'' and ''withincode'' primitive pointcuts and the ''void set*(..)'' signature pattern. **Tools:** The ''set'' and ''withincode'' primitive pointcuts and the ''void set*(..)'' signature pattern.
 </note> </note>
 +
 +You should get eleven warnings from this aspect. Notice that a lot of them are from within constructors. Actually, the common coding convention is that no private field should be assigned to outside of setter methods //or constructors//. Modify your answer to signal an actual error at compile time (rather than just a warning) when such an illegal assignment expression exists.
 +
 +<note tip>
 +**Tools:** Another ''withincode'' primitive pointcut and the ''new(..)'' constructor signature pattern.
 +</note>
 +
 +After you specify your pointcut correctly, you'll still find that the convention is violated twice in the figures package. You should see two errors in the ''move'' method of the ''Point'' class.
 +
 +----
 +
 +Don't correct these set statements. Instead, when done, disable your aspect: right-click on it and select **Build Path** -> **Exclude**. Continue with [[invariant:ex3|Exercise 3]].
invariant/ex2.1172422114.txt.gz · Last modified: 2007/02/25 17:48 by bdefrain