DEV Community


Discussion on: Facades should not have Working Plumbing

integerman profile image
Matt Eland Author

Often what I'll do is either use a private method inside the facade for standard error handling / logging if there's a lot of overlap or use a static class in C# with extension method support so, the class might look like this for logging:

public static ErrorExtensions {

  public void LogError(this Exception ex) {
    // Do some actual error logging here


and then in my handler I might do:

catch (InvalidOperationException ex) { 

If, for some reason, you have multiple facades in an application (can happen if you support different types of external callers, for example), you can extract a base class for all facades and add protected methods for these cross-cutting concerns.

The other thing you could consider is following an Action pattern where you have a single method that does standard stuff like validation and error handling and it just takes in a function that it invokes for the implementation-specific logic.

Forem Open with the Forem app