On Using Interface-types to Break Dependencies

Hayden Melton · 2006

It is a widely held belief that the structure of most real software systems does not compare favourably with the instructional literature on software design [FY00, Par96] [SM05, p.84]. In recent works [MT06, MT05] we have concentrated on collecting empirical evidence to support this belief. Particularly we have analysed compilation dependencies among the compilation units of many real, widely-used, openand closed-source Java applications. In performing this analysis we found that many applications have compilation units (1) involved in long dependency cycles [MT06] and (2) with excessive transitive dependencies [MT05]. These dependency characteristics are contrary to the design principles avoid dependency cycles among modules [Par78, Mar96b] [Lak96, p.185] and prefer a flatter rather than taller module dependency graph [Lak96, p.196] [Mar96a]. It is often the case that we want to improve the design of poorly-structured code [Fow99, p.55]. The use of an interface-type in place of a concrete-type is the crux of many techniques or strategies that purport to improve structure with respect to compilation dependencies. Examples of such techniques include Dependency Injection [Fow04, Fow05], Fowler’s Extract Interface refactoring [Fow99, p.341], Martin’s Dependency Inversion Principle [Mar96a] and Interface Segregation Principle [Mar96c], many of the Gang of Four Design Patterns (e.g., Observer) [GHJV95], Lakos’s Insulation Techniques [Lak96, ch.6], and Steimann’s advice [SSK03] and patterns [SM05] of interface use. In this paper we attempt to evaluate the efficacy of these interface-based techniques for breaking cycles and transitive dependencies. We do so from both a structural and conceptual perspective. We conclude that while these techniques are structurally very successful (i.e., they break most cycles and transitive dependencies) in many cases their result is not conceptually sound. That is to say, the resulting structure would be “better” if dependency was broken differently than by introducing an interface-type.

Read the paper · More papers on PaperTik