cs nov 6
shape s cannot be declared as the contructor for shape is protected...
Triangle T ( inherited for shape) is ok since derived classes can use protected member functions such as the constructor..
Triangle
-add(POint); vector<Point> points
Polygon also inherits everything from shape. it also has a vector of points and and has the add method for it.
struct Triangle : Shape
{
Triangle(p1,p2, p3, c)
:
{
p.add(point1);
};
}
struct Polygon : Closed_polyline {
{
void add(Point p); // add is different from shape so it is being overridden from Shape, there is an invariant no parallels and intersection..
void draw_lines() const;
};
open_polyline <- Closed_polyline<- Polygon
Polygon <- Triangle (so not needing a separate storage for points.
public :
Point point(int i) const {returns points[i]; } // read only access to points vector in the shape class.
Triangle - > Point (Association relationship, Point does not know about Triangle but Triangle can see point)
violet -- metauml diagram
Inheritance is a relationship between classes.
Association/Aggregation/Composition -- relationship between class and the objects in it or between objects. specific/concrete.
3 Relationships
is-a
has-a
uses
After refactoring ::
class Triangle : Polygon
{
Triangle ( )
{
this.add();
// the number of points cannot be more than 3;
}
Triangle T ( inherited for shape) is ok since derived classes can use protected member functions such as the constructor..
Triangle
-add(POint); vector<Point> points
Polygon also inherits everything from shape. it also has a vector of points and and has the add method for it.
struct Triangle : Shape
{
Triangle(p1,p2, p3, c)
:
{
p.add(point1);
};
}
struct Polygon : Closed_polyline {
{
void add(Point p); // add is different from shape so it is being overridden from Shape, there is an invariant no parallels and intersection..
void draw_lines() const;
};
open_polyline <- Closed_polyline<- Polygon
Polygon <- Triangle (so not needing a separate storage for points.
public :
Point point(int i) const {returns points[i]; } // read only access to points vector in the shape class.
Triangle - > Point (Association relationship, Point does not know about Triangle but Triangle can see point)
violet -- metauml diagram
Inheritance is a relationship between classes.
Association/Aggregation/Composition -- relationship between class and the objects in it or between objects. specific/concrete.
3 Relationships
is-a
has-a
uses
After refactoring ::
class Triangle : Polygon
{
Triangle ( )
{
this.add();
// the number of points cannot be more than 3;
}
