/World/Sweden/Linköping/LiU/IDA/PELAB/Adrian Pop/Teaching/ Design Patterns (TDDB84)

Mail: Adrian Pop
Dept. of Computer and Information Science
Linköpings universitet
581 83 Linköping, Sweden
Email: Email: adrpo@ida.liu.se
Phone: Phone: +46 (0)13 285781
Fax: Fax: +46 (0)13 142231
ULR: Building B, room 3B:478
ULR: Member of:
Software and Systems (SaS)
Programming Environments Laboratory (PELAB)
Documentation and Information Services (DIG)

Design Pattern (TDDB84) Labs of 2004

FAQ Lab 3

You can find answers I gave for Lab 3 here.
Please read these to understand how to create statements, etc, etc!

Lab 3, part 1

You have the subclass in origin variable. You have the superclass in superClass variable.
For the first part you should follow these steps:
  1. Find out which methods in origin that must be added to the superClass
    These are the methods that are:
    • public (private methods are not visible in the superclass remember) and
    • that are not already in the superClass.
    You use the methods signature to check whether it's already in superClass or not.

  2. Create new methods, by cloning them or building them from scratch, with the same signature as the respective methods from the origin class. The body of the methods should be empty, except from return statements.

  3. If the return type of the method [using method.getReturnType()] is:
      "int" add a return statement "return 0;" or some other int value
    • "bool" and a return statement "return true;" or false, doesn't matter
    • any other object add a return statement "return NULL;"
    to the method.

  4. Add the new methods you prepared to the superClass. USE "attach" to do that, otherwise Codemorpher won't realise the changes you are making.

Notes:

Use "attach" to attach the methods to the superClass. Otherwise the Codemorpher won't sense that change. Look into:
/home/TDDB84/codemorpher/jreb2/src/com/xptools/jrb/refactoring
to see more examples on how to use "attach"
In order to create statements (to add them to the empty methods) use:
ProgramFactory factory = ServiceRepository.getServiceConfig().getProgramFactory(); Return bodyStatement = factory.createReturn(fieldRef);
To compile go to your:
TDDB84/labs/lab3
change the FormSupersetInterface.java
then compile like this:
javac -d . -classpath ~TDDB84/codemorpher/jreb2/jar/codemorpher.jar *.java
Then run Codemorpher
~TDDB84/codemorpher/codemorpher
and test your stuff.
Also use System.out.println to test your transform code if problems appear.

Lab 3, part 2

NEW!! Detailed Instructions!

Updates

  • Last Updated in 2004-10-04


Page responsible: Adrian Pop
Last updated: 2005-10-21