#Adapter Pattern
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Categorization is a little arbitrary
But if you share what exactly you are thinking about I can maybe comment on whatever the design is
Okay so basically, I have 2 different packages.
package 1 has
public abstract class EmitterBase {
protected Boolean shouldEmit(Metadata metadata, ...){//Implementation and uses metadata twice
String config = metadata != null ? metadata.getConfig() : extractConfig();
return isEmittingEnabled(metadata, ...) &&
// config related stuff
}
private String extractConfig(){//Implementation}
}
Detected code, here are some useful tools:
public abstract class EmitterBase {
protected Boolean shouldEmit(Metadata metadata, ...) {
//Implementation and uses metadata twice
String config = metadata != null ? metadata.getConfig() : extractConfig();
return isEmittingEnabled(metadata, ...) && // config related stuff
}
private String extractConfig() {
//Implementation}
}
I want to remove metadata from the method signature and extract out config from it in a new interface
shouldEmit(String Config, …)
I want to then use an adapter pattern to allow any interface to use this new method by adapting
however there is going to be a template for all
which is:
if(shouldEmit()){
foo()
bar()
}
Detected code, here are some useful tools:
basically i just want to avoid duplication of code while using the adapter pattern
@alpine plank
Sorry I need a bit more concreteness to comment
You can use gist.github.com
All I'll say before that is that "avoiding repetition" and "X pattern" are heuristics
If those techniques help you understand stuff it's good, if they don't don't bother