#Adapter Pattern

1 messages · Page 1 of 1 (latest)

lean shard
#

Hi All, Im thinking of using the adapter pattern with a template method pattern. Is there an actual design pattern for this?

naive atlasBOT
#

<@&987246399047479336> please have a look, thanks.

naive atlasBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

alpine plank
#

Categorization is a little arbitrary

#

But if you share what exactly you are thinking about I can maybe comment on whatever the design is

lean shard
#

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}
}
naive atlasBOT
# lean shard Okay so basically, I have 2 different packages. package 1 has ```java public abs...

Detected code, here are some useful tools:

Formatted code
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}
  }
lean shard
#

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()
}
naive atlasBOT
lean shard
#

basically i just want to avoid duplication of code while using the adapter pattern

#

@alpine plank

alpine plank
#

Sorry I need a bit more concreteness to comment

#

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