Suppose there is a business function you need to implement, which sets some kind of a profile.
Depending on how data is received, however, setting profile will be implemented differently.
For instance parameters may be passed directly to the object which would be able to
setProfile();
or, parameters would have to be discovered and would have to be passed to profile by
setProfile(String[] data, Blah blooh);
What is the best approach in such situation? I mean, design wise how would you structure this?
I was thinking about using an Interface with abstract methods, which works, but introduces some noise. Not really sure how to best structure this.
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: