evolving_java-based_apis
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| evolving_java-based_apis [2014/02/06 06:46] – created yann | evolving_java-based_apis [2025/01/15 21:40] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| // | // | ||
| - | This document is very interesting because it tells all about Java-based API evolution in one document (okay, in three separate pages) without wasting space but going straight to the point. | + | This document is very interesting because it tells all about Java-based API evolution in one document (okay, in three separate pages) without wasting space but going straight to the point. |
| + | * Contract compatibility: | ||
| + | * Source code compatibility: | ||
| + | * Binary code compatibility: | ||
| + | * Data compatibility: | ||
| + | |||
| + | The document emphasises that source code compatibility is not necessary, because it argues that most API changes can be caught by the compiler and corrected by the developers. It is correct if the documentation regarding the transition between old and new API is sufficiently explicit for developers to easily find how to change their code. | ||
| + | |||
| + | Then, the document put forward the assumptions that "every aspect of the API matters to some Client" | ||
| + | |||
| + | Contract compatibility is the highest form of compatibility and the one that must be sought when evolving a Component. Contract compatibility depends on the role played by the Component and the Client and what kind of changes occurred between the two versions of the API. The roles are " | ||
| + | * a Component can offer an API and its implementation, | ||
| + | * a Component can offer a " | ||
| + | and the question is "For roles played by Clients, would the [...] API change render invalid a hypothetical Client making legal usage of the existing API?" The document then provides [[http:// | ||
| + | |||
| + | ^ Types of Changes | ||
| + | | Method preconditions | ||
| + | | ::: | Weaken | ||
| + | | Method postconditions | Strengthen | Contract compatible for callers | ||
| + | | ::: | Weaken | ||
| + | | Field invariants | ||
| + | | ::: | Weaken | ||
| + | | Adding an API method: | ||
| + | | - To an interface | ||
| + | | - To a class((Intended to be sub-classed by implementors)) || Contract compatible for callers | ||
| + | | - To a class((Not to be sub-classed by implementors)) | ||
| + | |||
| + | Then, the document goes on enumerating, | ||
| + | * API packages; | ||
| + | * API interfaces (methods, fields, and type members); | ||
| + | * API classes (methods and constructors, | ||
| + | |||
| + | The document also discusses annotations on API constituents, | ||
| + | |||
| + | Finally, the document includes several suggestions to design better API or make it easier to change them: | ||
| + | * Clients must only use published (not internal), API (even if other constituents are public); | ||
| + | * " | ||
| + | * "[A]ll gender changes involving classes, enums, interfaces, and annotation types break binary compatibility [...]"; | ||
| + | * "[A] pre-existing Client subclass of an existing implementation might still provide a pre-existing implementation [of a newly added method, by sheer luck]"; | ||
| + | * "API interfaces that Clients should implement should not include fields", | ||
| + | * " | ||
| + | * "API classes should always explicitly declare at least one constructor"; | ||
| + | * " | ||
| + | * " | ||
| + | * "Java compiler always inline the value[s] of constant fields [...] this does not meet the objective of changing the API field' | ||
| + | * "As long as the erasure looks like the corresponding declaration prior to generification, | ||
| + | * " | ||
| + | * "[T]ag all stored data with its format version number"; | ||
| + | * " | ||
| + | |||
| + | Also, the document provides the simplest, clearest explanation of Java 1.5+ type erasure mechanism, that I reproduce here for the sake of beauty: | ||
| + | |||
| + | >> A raw type is a use of a generic type without the normal type arguments. For example, " | ||
| + | >> | ||
| + | >> The term erasure is suggestive. Imagine going through your code and literally erasing the type parameters from the generic type declaration (e.g., erasing the "< | ||
evolving_java-based_apis.1391669186.txt.gz · Last modified: (external edit)
