DEV Community

Discussion on: Coding Best Practices Part 1 (Naming Conventions & Class Designing Principles)

Collapse
 
aromauniversity profile image
Mountain Lover

In your IShape code example, it isn't clear for me what is desirable to meet Interface Segregation Principle (ISP). Should IShape only have getArea () method only not to force Circle to have getWidth() method?

Collapse
 
mohitrajput987 profile image
Mohit Rajput

Yes. If IShape has the only getArea() method, it can be used in any shape i.e. Rectangle, Circle, Triangle to the area of that shape. The circle doesn't have width or height so Circle class itself can have a method called getRadius(). Similarly Rectangle can have getWidth() and getHeight().