In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
This is my previous study note on the six principles of object-oriented, in which the understanding of the Richter substitution principle is not deep enough, https://blog.51cto.com/zhangzhao/2396810.
According to Baidu encyclopedia, the Richter substitution principle is defined as: Liskov proposed a principle of inheritance "Inheritance should ensure that any property proved about supertype objects also holds for subtype objects."-"inheritance must ensure that the properties owned by the superclass are still valid in the subclass." That is, an is-A relationship exists only when an instance of a subclass should be able to replace any instance of its superclass.
To put it simply, when a subclass replaces its base class, the behavior of the program does not change.
This requires:
1. Subclasses can implement the abstract methods of the parent class, but cannot override the non-abstract methods of the parent class. (here we need to distinguish between the concept of rewriting and overloading, which means that the function name is the same and the signature or parameter type of the function is the same, while overloading means that the function name is the same and the signature or parameter type of the function is different. The polymorphism of the object-oriented language will automatically match the most appropriate function at run time according to the passed argument type.)
two。 Subclasses can add their own features.
3. When the parent method of the subclass is overloaded, the precondition (formal parameter) of the method is more relaxed than the input parameters of the parent method. This is because if the parameter range of the subclass method is smaller, the overloaded function of the subclass may be called first when the calling function is run, which violates the Richter substitution principle.
4. The output (return value) can be reduced when the parent method is overloaded.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.