正在加载图片...
$2.2 METHOD AND LANGUAGE 27 associated features,and,more prosaically,as a "tax-deductible item",which earns some deduction at tax time.Inheritance is justified in both cases.Multiple inheritance is the guarantee that a class may inherit not just from one other but from as many as is conceptually justified. Multiple inheritance raises a few technical problems,in particular the resolution of name clashes(cases in which different features,inherited from different classes,have the same name).Any notation offering multiple inheritance must provide an adequate solution to these problems. It should be possible for a class to inherit from as many others as necessary. with an adequate mechanism for disambiguating name clashes. The solution developed in this book is based on renaming the conflicting features in the heir class. Repeated inheritance Multiple inheritance raises the possibility of repeated inheritance,the case in which a class inherits from another through two or more paths,as shown. Repeated inheritance Inherits from In such a case the language must provide precise rules defining what happens to features inherited repeatedly from the common ancestor,4 in the figure.As the discussion of repeated inheritance will show,it may be desirable for a feature of4 to yield just one feature of D in some cases (sharing),but in others it should yield two (replication). Developers must have the flexibility to prescribe either policy separately for each feature. Precise rules should govern the fate of features under repeated inheritance, allowing developers to choose,separately for each repeatedly inherited feature,between sharing and replication. Constrained genericity The combination of genericity and inheritance brings about an important technique, constrained genericity,through which you can specify a class with a generic parameter that represents not an arbitrary type as with the earlier(unconstrained)form of genericity, but a type that is a descendant of a given class.§2.2 METHOD AND LANGUAGE 27 associated features, and, more prosaically, as a “tax-deductible item”, which earns some deduction at tax time. Inheritance is justified in both cases. Multiple inheritance is the guarantee that a class may inherit not just from one other but from as many as is conceptually justified. Multiple inheritance raises a few technical problems, in particular the resolution of name clashes (cases in which different features, inherited from different classes, have the same name). Any notation offering multiple inheritance must provide an adequate solution to these problems. The solution developed in this book is based on renaming the conflicting features in the heir class. Repeated inheritance Multiple inheritance raises the possibility of repeated inheritance, the case in which a class inherits from another through two or more paths, as shown. In such a case the language must provide precise rules defining what happens to features inherited repeatedly from the common ancestor, A in the figure. As the discussion of repeated inheritance will show, it may be desirable for a feature of A to yield just one feature of D in some cases (sharing), but in others it should yield two (replication). Developers must have the flexibility to prescribe either policy separately for each feature. Constrained genericity The combination of genericity and inheritance brings about an important technique, constrained genericity, through which you can specify a class with a generic parameter that represents not an arbitrary type as with the earlier (unconstrained) form of genericity, but a type that is a descendant of a given class. It should be possible for a class to inherit from as many others as necessary, with an adequate mechanism for disambiguating name clashes. Precise rules should govern the fate of features under repeated inheritance, allowing developers to choose, separately for each repeatedly inherited feature, between sharing and replication. Repeated inheritance Inherits from A D
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有