Are we ready for a safer construction environment?

11Citations
Citations of this article
8Readers
Mendeley users who have this article in their library.
Get full text

Abstract

The semantics of many OO languages dictates that the constructor of a derived class is a refining extension of one of the base class constructors. As this base constructor runs, it may invoke dynamically bound methods which are overridden in the derived class. These invocations receive an "half baked object", i.e., an object whose derived class portion is uninitialized. Such a situation may lead to confusing semantics and to hidden coupling between the base and the derived. Dynamic binding within constructors also makes it difficult to enhance the programming language with advanced mechanisms for expressing design intent, such as non-null annotation (denoting reference values which can never be null), read-only annotation for fields and variables (expressing the intention that these cannot be modified after they are completely created) and class invariants (part of the famous design by contract methodology). A read-only field for example becomes immutable only after the creation of the enclosing object is complete. We investigate the current programming practice in JAVA of calling dynamically bound methods. In a data set comprising a dozen software collections with over sixty thousand classes, we found that although the potential for such a situation is non-negligible (prevalence > 8%), i.e., there are many constructors that make calls to methods which may be overridden in derived classes, actual such dynamic binding is scarce, found in less than 1.5% of all constructors, inheriting from less than 0.5% of all constructors. Further, we find that over 80% of these incidents fall into eight "patterns", which can be relatively easily transformed into equivalent code which refrains from premature method invocation. A similar predicament occurs when a constructor exposes the self identity to external code, which then invokes methods overridden in the derived class. Our estimate on the prevalence of this exposition is less accurate due to the complexity of interprocedural dataflow analysis. Although the estimate is high, there are indications that it arises from a relatively small number of base constructors.© 2009 Springer Berlin Heidelberg.

Cite

CITATION STYLE

APA

Gil, J., & Shragai, T. (2009). Are we ready for a safer construction environment? In Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics) (Vol. 5653 LNCS, pp. 495–519). https://doi.org/10.1007/978-3-642-03013-0_23

Register to see more suggestions

Mendeley helps you to discover research relevant for your work.

Already have an account?

Save time finding and organizing research with Mendeley

Sign up for free