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:
- 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.
- 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
- 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;"
- Add the new methods you prepared to the superClass. USE "attach" to do that, otherwise Codemorpher won't realise the changes you are making.
Use "attach" to attach the methods to the superClass. Otherwise the Codemorpher won't
sense that change. Look into:
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:
change the FormSupersetInterface.java
then compile like this:
javac -d . -classpath ~TDDB84/codemorpher/jreb2/jar/codemorpher.jar *.java
Then run Codemorpher
and test your stuff.
Also use System.out.println to test your transform code if problems appear.
Lab 3, part 2
- Last Updated in 2004-10-04
Page responsible: Adrian Pop
Last updated: 2005-10-21