Javascript Inheritance Mechanism instance

Source: Internet
Author: User

In fact, there are only two kinds of geometric shapes: an elliptical shape (circular shape) and a Polygon Shape (having a certain number of edges ). A circle is an elliptical type with only one focal point. Triangles, rectangles, and Pentagons are polygon with different numbers of edges. A square is a type of rectangle with equal lengths of all edges. This constitutes a perfect inheritance relationship.

In this example, Shape is the base class of Ellipse and Polygon (inherited from all classes ). An ellipse has an attribute.Foci, Indicating the number of focal points that an elliptic has. The Circle inherits the elliptical shape, so the circular shape is a subclass of the elliptical shape (subclass) and the elliptical shape is a superclass of the circular shape (superclass ). Likewise, triangles, rectangles, and Pentagons are subclasses of polygon, and polygon are their superclasses. Finally, Square inherits the rectangle.

It is best to use diagrams to explain this inheritance relationship, which is the application of UML (Unified Modeling Language. One of the main purposes of UML is to visually represent complex object relationships such as inheritance. Figure 4-1 is a UML diagram that explains the relationship between a Shape and its subclass.

In UML, each box represents a class, which is described by the class name. The line segments at the top of the Triangle, Rectangle, and Pentagon are combined to point to the Shape, indicating that these classes are inherited by the Shape. Similarly, the arrow pointing from Square to Rectangle illustrates the inheritance relationship between them.

If you are interested in learning UML, you can refer to the "UML User Guide (second edition)" by the three UML founders.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.