Veröffentlichter Bericht einer Hochschule/Institution,

Java Traits -- Improving Opportunities for Reuse

.
CSE-04-005. Department of Computer Science and Engineering OGI School of Science & Engineering Oregon Health & Science University, 20000 NW Walker Road Beaverton, OR 97006-8921 USA, (September 2004)

Zusammenfassung

One goal of Object-Oriented Programming is to enable programmers to craft elegant and reusable systems. In practice however, Java programmers have no choice but to copy and paste code that cannot be shared via inheritance. The resulting duplication makes systems diffcult to understand and hard to maintain. Traits are a language feature, originally prototyped in Smalltalk, that directly address this barrier to reuse. Traits encapsulate collections of methods that can be reused anywhere in the inheritance hierarchy. We argue that Java would benefit from such a mechanism. To demonstrate, we present a case study of Java Swing, a large production- quality library, showing how we isolated pieces of duplicated code that could not be eliminated by conventional means and how traits could be used to eliminate them. In addition to a lack of multiple inheritance, our study revealed other barriers to reuse, including the use of private, final and synchronized qualifiers. Surprisingly, these are all easily overcome by a natural extension of traits.

Tags

Nutzer

  • @gron

Kommentare und Rezensionen