This violates the ISP principle in SOLID, can someone explain why and refactor? Thank you!
...
50.1K
Verified Solution
Link Copied!
Question
Programming
This violates the ISP principle in SOLID, can someone explain why and refactor? Thank you! public interface IGesture { void OnClick(); void OnSwipe(); void OnDoubleClick(); } public class LaunchButton : IGesture { public void OnClick() { //Launch nuclear missiles } public void OnDoubleClick() { throw new NotImplementedException(); } public void OnSwipe() { throw new NotImplementedException(); } }
Answer & Explanation
Solved by verified expert
3.8 Ratings (620 Votes)
Hi Interface Segregation Principle is The Class should have implemented only those interface methods or elements that are necessary for that particular class If there are unnecessary elements are available in the interface which implemented by the class then segragate the interface and declare only realted elemtns into it and user that in the class In the above example Class does not follow the Interface Segregation Principle because Class LaunchButton does not need to Implement the below functions
See Answer
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
Unlimited Question Access with detailed Answers
Zin AI - 3 Million Words
10 Dall-E 3 Images
20 Plot Generations
Conversation with Dialogue Memory
No Ads, Ever!
Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!