The Interface Segregation principle states that:
Clients should not be forced to depend on methods that they do not use.
In the Null object pattern the Null class that implements the interface does nothing with it. Which is intentional.
But, it is depending on methods that it doesn't use. Or does it not break the principle because it actually does simply just depend on it by not doing anything in the implemented methods?
Typically, the Null object pattern does not take any dependencies. Here is how a typical Null object looks like:
public class NullDataStore : IDataStore
{
public void StoreData(Data data)
{
}
}
The NullDataStore
class in this case has no dependencies and therefore it does not depend on methods that it does not use. So it does not break the ISP.