public class GraphicDesigner
public void Draw(Shape s)
It only takes the Shape object it needs to draw and simply calls it’s Draw method. Shape class is our abstraction and all the GraphicDesigner class needs to know is that it will get a Shape object and it needs to call its Draw method. Whether that Shape is a Rectangle or Triangle is not a concern of the GraphicDesigner class.
Now with our new logic, we can easily introduce new shapes and draw them without modifying the GraphicDesigner class. For example, if we need to introduce the Triangle class, we will simply need to inherit it from the Shape class and our logic inside GraphicDesigner class will not change. Our code now does not violate the Open Closed Principle and is much easier to maintain also.
In the upcoming article, we will take a look at the third principle in SOLID principles which is the Liskov Substitution Principle. Till then Happy Coding!