Tuesday, 15 September 2015

C++ Multiple Inheritance to Implement Polymorphism -


, a diagram of the abstract base class and several effects in AV rule 87.

  1. What is the attempt of showing this picture?

  2. In this example, what is the purpose of a private / protected heritage?

  3. How does an implementation form a base class?

  4. Dimension from AV rule 87 shows that D1 is inherited from an implication; Is this difference a separate implementation that has no interaction with the interface?

AV rule 87

The hierarchy should be based on abstract classes. See Strawstrup 2, 12.5.

Logic: Hierarchy focuses on creating clean interface based on abstract classes, keep implementation details out of the interface, and compile Reduce the dependency, while allowing alternate variations to be kept together. For example, refer to AV Rule 87 in Appendix A. The hierarchy based on

...

Appendix A - AV Rule 87

is an abstract class favorite, so on top of the picture The hierarchy located is liked on the hierarchy at the bottom of the picture. JSF AV Rule 87

Example of the use of classic polymorphism:

classic size polymorphic example

5 Will my implementation be the following ? It does not look right to me; I'm scared, I'm missing the purpose of design. Traditionally, I expect the right triangle to inherit the triangle.

  class shape {}; // interface class right_Triangle {}; // Imple class triangle: public shape, private right to treat {}; // D1  

Your example is mostly correct, and adherence to the spirit of AV 87 You have made a typo, however, the implementation and public class should be of the same "type" (therefore, both should be a normal triangle, for example):

  class ishape {...}; Square triangle impl {...}; Square Triangle: Public IShape, Private Triangle Impl {...};  

This diagram shows that a right triangle a triangle is wrong , and a common misconception is not a right triangle triangle As long as you do not explicitly limit what you can do with a triangle (eg, just read it). In a triangle that has some edge length, it can be. The class inherited from a triangle should still act as a triangle * known as it.

Since you can not RightTriangle class can be used everywhere without a triangle class of a concrete square In the form of triangle useless limitations (you can not set the length of the edge on a triangle) - In this way the heritage hierarchy is shown just bad design.

The design of a hierarchy of a class does not necessarily follow a vane diagram, nor should it follow "truth everyday". Long software engineering practice shows that when you stick to the LSP, you get intelligent heritage diagrams.

Yes, textbooks that "display the right triangle" pain are incorrect If they do not offer solid design satisfying LCP, in the case of shapes, Trilateral and quadrilaterals interfaces should be read only, and specific top- or side-installed methods can be presented only in derivative classes, because they are different Adhere Whether derivative concrete classes require a flat hierarchy (a class is not a rectangular - if this happens then you can set the length of two different edges for it Are!). Similarly, as far as LSP goes, there is not a square a quadrilateral , since it can be crisp as a quadrilateral, etc.


No comments:

Post a Comment