Interface Segregation Principle (ISP)

The Interface Segregation Principle (ISP) states that no client should be forced to depend on interfaces they do not use. This means classes should not have to implement methods they do not use.

Bad Example:

An `IPrinter` interface has `Print`, `Scan`, and `Fax` methods. A `SimplePrinter` class implements `IPrinter` but throws an exception in the `Scan` and `Fax` methods, because it can only print. This violates the ISP.

                    
                    interface IPrinter {
                        void Print();
                        void Scan();
                        void Fax();
                    }

                    class SimplePrinter : IPrinter {
                        public void Print() {
                            // Implementation...
                        }

                        public void Scan() {
                            throw new NotImplementedException();
                        }

                        public void Fax() {
                            throw new NotImplementedException();
                        }
                    }
                    
                    

Corrected Example:

A better design would be to segregate the `IPrinter` interface into `IPrinter`, `IScanner`, and `IFax`.

                    
                    interface IPrinter {
                        void Print();
                    }

                    interface IScanner {
                        void Scan();
                    }

                    interface IFax {
                        void Fax();
                    }

                    class SimplePrinter : IPrinter {
                        public void Print() {
                            // Implementation...
                        }
                    }