I'm trying to refactor my code by using a BaseComponentType
class and inheriting from this in my ElectricalComponentType
class (and similar child classes), as follows:
BaseComponentType.java
public abstract class BaseComponentType {
public static BaseComponentType findByUid ( Class klass, String uid ) {
return new Select().from( klass ).where( "uid = ?", uid ).executeSingle();
}
}
ElectricalComponentType.java
public class ElectricalComponentType extends BaseComponentType {
public static ElectricalComponentType findByUid( String uid ) {
return (ElectricalComponentType) findByUid( ElectricalComponentType.class, uid );
}
}
What I need to do is call ElectricalComponentType.findByUid( 'a1234' )
but it would be great if I did not have to define findByUid
in the ElectricalComponentType
class and instead could inherit this functionality from the BaseComponentType
.
You'll notice that two things stand in the way:
I need the
ElectricalComponentType
class in thefindByUid
parent method.I need to return
ElectricalComponentType
object (or whatever the child class object is) instead of aBaseComponentType
class object.
Is there a way to do this?