CPSC 2150 - DAY 3 AUGUST 25, 2016 ================================================================================ Alias - two pointers pointing to the same data Whenever you pass something as a parameter, a copy to the pointer is created. When you pass a primitive, the value is copied. Arrays get passed by reference. Immutability ------------ value can never change Wrapper classes are immutable, no aliasing worries Motivation for Modular Design ----------------------------- Seperation of concerns Independent development by team members Bug localization Ease of evolution and maintenance Design By Contract ------------------ Also known as programming to the interface Articulated clearly only in the 1980s There are component providers (implementers) and users (clients) Implementers and clients communicate through contracts Contracts "hide information" by design, because they are irrelevant for client Contracts may be formal or informal but they must be understandable to clients so hidden infor cannot be used Contract for an Operation ------------------------- A requires clause (precondition) that characterizes the responsibility of the caller -not all operations have a requires clause An ensures clause (postcondition) that characterizes the responsibility of the code that implements that operation -Implementer assumes the requires clause -Ensures clause is guarateed only if the caller satifies the requires clause. Programmer assumes that client satisfies requires clause. Why use Ensures Clauses ----------------------- Withouth them, how can a user know what the operation does? .names alone can't tell the whole story! .Don't want users to have to look at code! Defeats the vvery idea of using design by contract Why use Requires Clauses ------------------------ .Efficiency .In the absence of required clauses, implementations will not work. Operation to binary search -Requires that array is sorted -Ensures that it returns true if the item is in the array, false otherwise Integer division operations -Don't divide by zero -It's the user responsibility -because efficiency Javadoc ------- The standard documentation technique for Java is called Javadoc You place special Javadoc comments in /** / API --- The resulting documentiation is known as an API (Application Programming Interface)