Skip to main content
Don't use code formatting for emphasis. Fix typos. Add syntax highlighting.
Source Link
wjandrea
  • 33.9k
  • 10
  • 69
  • 105

Inheritance expresses aan is-ais-a relationship, while composition expresses a has-ahas-a relationship between the two classes.

An example for composition is a polygon. It has aan ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 
struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 
struct logic_error : public exception { }; 

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has a ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 

Inheritance expresses an is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has an ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 
someone already fixed the question
Source Link
sbi
  • 225k
  • 46
  • 267
  • 447

Containership isn't a common term. I think you mean Composition.

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has a ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 

Containership isn't a common term. I think you mean Composition.

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has a ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has a ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 
added 260 characters in body
Source Link
pmr
  • 60k
  • 11
  • 120
  • 162

Containership isn't a common term. I think you mean Composition.

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has a ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 

Containership isn't a common term. I think you mean Composition.

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

Containership isn't a common term. I think you mean Composition.

Inheritance expresses a is-a relationship, while composition expresses a has-a relationship between the two classes.

An example for composition is a polygon. It has a ordered sequence of Points. In C++ terms:

struct Polygon { std::vector<Point> points; }; 

While an logic_error is a exception:

struct logic_error : public exception { }; 
Source Link
pmr
  • 60k
  • 11
  • 120
  • 162
Loading