SOLID – Open close principle implemented in golang

Notice: Draft version

This is just draft version of how we organize code structure to follow open close principle in golang

Todo: class diagram

Shape interface, define must have GetArea() function

Then Square struct which implement Shape interface

Same as Square struct, the Circle struct

Then ShapeManager struct

Then, the main.go file

Whenever you add more type of shape, for eg: a rectangle:

It’s convenience when we wanna add more types of Shape and follow the O principle in SOLID

Gist file:

Leave a Reply

Your email address will not be published. Required fields are marked *