_Design Guidelines for IS-A Hierarchies_
by John A. Grosberg

    
Listing One
class Rectangle {
    public:
        Rectangle(int l, int w):length(l),width(w){}
        void set_length(int l) {length = l;}
        void set_width(int w) {width = w;}
        virtual int area(void){return (length*width);}
        virtual int perimeter(void) {return (2*(length+width));}
    private:
        int length;
        int width;
};
class Square: public Rectangle {
    public:
        Square(int s):Rectangle(s,s){}
        void set_side(int s) {set_length(s); set_width(s)};
};
// Make some instances:
Rectangle R1(3,5);
Square    S1(7);

Listing Two
class ARectangle {
    public:
        virtual int area(void) = 0;
        virtual int perimeter(void) = 0;    
        virtual ~ARectangle() = 0;      
};
class Rectangle: public ARectangle{
    public:
        Rectangle(int l, int w):length(l),width(w){}
        void set_length(int l) {length = l;}
        void set_width(int w) {width = w;}
        int area(void){return (length*width);}
        int perimeter(void) {return (2*(length+width));}
    private:
        int length;
       int width;
};
class Square: public ARectangle {
    public:
        Square(int s):side(s){}
        void set_side(int s) {side = s;}
        int area(void){return (side*side);}
        int perimeter(void) {return (4*side);}
    private:
        int side;
};
// Make some instances:
Rectangle R1(3,5);
Square    S1(7);
ARectangle *pAR = &S1;

Listing Three
class ARectangle {
    public:
        virtual int area(void) = 0;
        virtual int perimeter(void) = 0;            
        virtual ~ARectangle() = 0;      
};
class CRectangle: public ARectangle, private Rectangle{
    public:
        CRectangle(int l, int w):Rectangle(l,w){}
        void set_length(int l) {Rectangle::set_length(l);}
        void set_width(int w) {Rectangle::set_width(w);}
        int area(void){return Rectangle::area();}
        int perimeter(void) {return Rectangle::perimeter();}
};
class CSquare: public ARectangle {
    public:
        CSquare(int s):side(s){}
        void set_side(int s) {side = s;}
        int area(void){return (side*side);}
        int perimeter(void) {return (4*side);}
    private:
        int side;
};
// Make some instances:
CRectangle R1(3,5);
CSquare    S1(7);
ARectangle *pAR1 = &S1;
ARectangle &rAR2 = R1;

Listing Four
class CRectangle: public ARectangle{
    public:
        CRectangle(int l, int w):rect(l,w){}
        void set_length(int l) {rect.set_length(l);}
        void set_width(int w) {rect.set_width(w);}
        int area(void){return rect.area();}
        int perimeter(void) {return rect.perimeter();}
    private:
       Rectangle rect;
};




Figure 1: 




Figure 2: 




Figure 3:






Figure 4: 






Figure 5: 








Figure 6:





Figure 7:






Figure 8:







Figure 9(a)




Figure 9(b) 






