I think this is covered by Ch10 from the final Jython tutorial
In this example, the author uses the BuildingType interface, which can be changed to an abstract class
public abstract class BuildingType { public abstract String getBuildingName(); public abstract String getBuildingAddress(); public abstract String getBuildingId(); @Override public String toString(){ return "Abstract Building Info: " + getBuildingId() + " " + getBuildingName() + " " + getBuildingAddress(); } }
which you can expand with your own methods, in this case I added toString() and used it in 'print' instead of the author’s source code:
public class Main { private static void print(BuildingType building) { System.out.println(building.toString()); } public static void main(String[] args) { BuildingFactory factory = new BuildingFactory(); BuildingType building1 = factory.create("BUILDING-A", "100 WEST MAIN", "1") print(building1); BuildingType building2 = factory.create("BUILDING-B", "110 WEST MAIN", "2"); print(building2); BuildingType building3 = factory.create("BUILDING-C", "120 WEST MAIN", "3"); print(building3); } }
You can duplicate this code using the code from CH10 in the Definition Guide for Jython, and all credits should be sent to the author - I just changed Interface to the Abstract class.
You will also consider using the default Java 7 method in the interface.
Grahama
source share