PRINCIPLE OF INTERFACE SEGREGATION
Nenhuma classe deve ser dependente de métodos que não precisa. Um exemplo seria uma interface “Máquina”, que força os métodos print( ) , scan( ) e fax( ) . Nem toda máquina tem esses 3 métodos. Então criamos as interfaces IPrinter , IScanner e IFax . Agora uma máquina assina apenas os contratos que realmente precisa e cumpre apenas esses. Exemplo de Código (Opcional - Ilustrando o texto): // ❌…
The article discusses the Interface Segregation Principle (ISP), a concept in software development. It states that a class should not depend on methods it doesn't need, and that interfaces should be reusable and specific. A bad example is given of a large interface, IUserActions, that forces a StandardUser class to implement unnecessary methods.
A good example is then provided, where the interface is broken down into smaller, specific ones, such as IReader, IWriter, and IAdmin, allowing classes to implement only what they need. This approach makes the code more modular and easier to maintain.
Written by urgent.news from Dev.to's report — not a translation of it. Machine-written — may contain errors; check the original before relying on it.