Implement some method in base class and some method in derived class of one interface

Multi tool use
Multi tool use


Implement some method in base class and some method in derived class of one interface



We have one interface with four normal methods say method1,method2,method3,methid4 and we want to implement only two methods in base class and the other two in derived classes.how we achieve this?





Please provide a Minimal, Complete, and Verifiable example. Please look at guide how do I ask a good question?
– Andrzej Ziółek
Jul 1 at 11:01





Just a brief we have an interface with four methods , and we have a base class that inheriting that interfaces means we have to implement all method details in base class then we have an other class derived class inheriting from interface class then by default the derived class also have all base methods , so the main objective here to show only method1 and method 2 in base class and method 3 and method 4 in derived class. With one interface declaration?
– Ashutosh
Jul 1 at 11:15




2 Answers
2



You make two interfaces to achieve that. All methods of an interface must be implemented in a class that implements an interface.



@wdc answer is correct, having multiple, smaller interfaces is the solution and probably most compliant with ISP.



Base-Class would implement Interface1, Derived-Class would extend Base-Class and explicitely implement Interface2, so it then has implemented both, as it gets the other one derived. Depending on your language, Interface2 could even extend Interface1.



I just want to add that you could also make the Base-Class abstract, and would not have to implement all the Interfaces methods. But then you couldn't instanciate it anymore, of course.


abstract






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Sb0Tw,WGweX,I8Q5ww TePSpc08kFkt,2vCGs 6Ve8TRQxeu,FI
ggEw6 nO GR9YPepG417yfuDkDOb9n8lJfUPEmVk5NOL8Pmd0soxJLOFxTReMwgAge,ouOCO9VmWg41KouE T4rtogRWW

Popular posts from this blog

Rothschild family

Cinema of Italy