What is tracing modeling (Java)

Source: Internet
Author: User
Tags inheritance

It is called this name, in addition to a certain historical reasons, but also because in the traditional sense, the method of the class inheritance graph is the root at the top, and then gradually downward expansion (of course, according to their own custom in any way to depict this diagram). Factor, Wind.java's inheritance diagram looks like this:

Since the orientation of the shape is derived from the class to the base class, the arrow is facing up, so it is usually called "back shape", that is, upcasting. Tracing back styling is certainly safe, as we are from a more specific type to a more conventional type. In other words, a derived class is a superset of the underlying class. It can contain more methods than the underlying class, but it contains at least a method of the underlying class. The only problem with a class interface that can be traced is that it may lose the method rather than win it. This is the reason why the compiler allows you to trace the shape without any definite styling or other special annotations.
You can also perform a retrospective, but you will face a dilemma that is detailed in the 11th chapter.

1. Re-discussion on synthesis and inheritance
In object-oriented programming, one of the most likely ways to create and use code is to encapsulate data and methods in a single class and use objects of that class. Sometimes it is necessary to construct new classes with ready-made classes using the "compositing" technique. And inheritance is one of the most uncommon practices. Thus, while inheritance has gained a lot of emphasis in learning OOP, it does not mean that it should be used everywhere as much as possible. On the contrary, use it with particular caution. It can only be considered if it is clear that inheritance is most effective in all methods. One of the easiest ways to determine if you should choose to synthesize or inherit is to consider whether you need to return to the base class from a new type. If you must go back, you need to inherit. But if you do not need to go back to modelling, you should remind yourself to prevent the abuse of inheritance. In the next chapter (polymorphism), you will be presented with an occasion that must be traced back to the form. But just remember to always ask yourself, "Do I really need to go back to modeling?", the choice of synthesis or inheritance should not be too big a problem.

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.