I've been looking at the interfaces in Jade with a view to removing some of the code duplication (effectively the same methods on two or more classes) and wondering if they could be made more flexible. Specifically whether the interfaces could
- Allow methods on the interface to be mapped to properties on real classes (effectively a Get method)
- Allow methods to be written on the interface (rather than just mapping to existing methods on real classes)
For example consider a form that is used to record a production run for a bill of materials (e.g. making a bike from it's components.) It's likely that transients are used to store the details of the run prior to the user saving it and that the system would calculate the details of the stock used for the run to display to the user (e.g. 10 bikes would use 10 frames, 20 wheels etc.) A similar piece of code may also exist on the persistent data classes to do the same calculation for a stored run, e.g. what stock was actually used. Similar scenarios may exist for calculating interest on savings or mortgages etc.
I'm wondering if it would be useful to put the calculation method on an interface and then map Get methods on the interface to the underlying data in the persistent and transient structures (obviously the transient and persistent structure would need to be similar.)
An interface used to calculate interest on a mortage may have the following Get methods mapped to the data
- getTerm
- getInterestRate
- getPrinciple
and a calculateInterest method defined on the interface which calls these get methods.