I would go by abstracting the actual profile to its own class hierarchy to encapsulate it and add Generics to the setProfile()
. Granted, it does add some complexity but because it also introduces indirection, the code will be more decoupled which in the long run should prove useful.
Also the actual function could be in its own class hierarchy entirely to make that part pluggable too which would mean that you'd have a Strategy Pattern in your hands. The decision to apply this, however, would require more knowledge of the system you're building and may not be suitable for what you're building.
Quick example:
/**
* Interface for describing the actual function. May (and most likely does)
* contain other methods too.
*/
public interface BusinessFunction<P extends Profile> {
public void setProfile(P p);
}
/**
* Base profile interface, contains all common profile related methods.
*/
public interface Profile {}
/**
* This interface is mostly a matter of taste, I added this just to show the
* extendability.
*/
public interface SimpleProfile extends Profile {}
/**
* This would be what you're interested of.
*/
public interface ComplexProfile extends Profile {
String[] getData();
Blah blooh();
}
/**
* Actual function.
*/
public class ComplexBusinessFunction implements BusinessFunction<ComplexProfile> {
public void setProfile(ComplexProfile p) {
// do whatever with p which has getData() and blooh()
}
}
/**
* And another example just to be thorough.
*/
public class SimpleBusinessFunction implements BusinessFunction<SimpleProfile> {
public void setProfile(SimpleProfile p) {
// do whatever with the empty profile
}
}