Create a base class for a Square and a Triangle, then design a Shape base class and explain the relationships and inheritance structure between them.