0

Consider (in C# just as an example) an interface:

interface ILog
{
   void log(string text);
}

Which has the following implementations:

class GUILog : ILog
{
   public log(string text)
   {
      MessageBox.Show(text);
   }
}

class ConsoleLog : ILog
{
   public log(string text)
   {
      Console.WriteLine(text);
   }
}

class FakeLog : ILog
{
   public log(string text)
   {
      //Do nothing
   }
}

Is there a common naming convention for something like 'FakeLog'. Note that the logging context is just an example. The general idea is more that you have an implementation which does nothing...how should you name that? Of course you must assume the client doesn't rely on the implementation doing something to operate correctly. 'Mock' is perhaps close but is more from the testing side of things, and in this case no calls are logged. Maybe 'NOOP'?

user109078
  • 906
  • 7
  • 19
  • 1
    Possible duplicate of [Design pattern for default implementation with empty methods](https://stackoverflow.com/questions/1259495/design-pattern-for-default-implementation-with-empty-methods) – jaco0646 Mar 01 '19 at 21:06
  • Does my answer helped you somehow with your question? – Michał Ziober Mar 27 '19 at 19:31

1 Answers1

0

There is no standard name. But we can find one using clean code principles:

  • Pick one word per concept. Be consistent.
  • Good name should describe business and solution domains.
  • If there is a design pattern, use it.

Actually, we have one name and it is NullObject. Take a look on Null Object Design Pattern:

The intent of a Null Object is to encapsulate the absence of an object by providing a substitutable alternative that offers suitable default do nothing behavior. In short, a design where "nothing will come of nothing"

Use the Null Object pattern when

  • an object requires a collaborator. The Null Object pattern does not introduce this collaboration--it makes use of a collaboration that already exists
  • some collaborator instances should do nothing
  • you want to abstract the handling of null away from the client

Below:

class NullLog : ILog {
...
}

implies that you want to log to null which means you want to throw it away.

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146