Saturday, January 27, 2007

Lecture 10

  • Delegation within the class definition
    • code is sometimes used over and over within the methods of a class
    • constructors =>implement the constructor that takes all possible arguements and call that constructor from the other constructors.
  • why do this?
    • saves you time
    • making changes is much easier, and less error prore(eg. you might miss a change.)
  • Constructor Fields(final keyword)
    • best practice to use a variable to store any constants used by your program
    • want these values to be protected from change
  • public final int CONSTANTS = s;
    • constant is initially given the value s
    • no entity in the program is allowed to alter constant
    • final entities must be initialized on the same line that they are declared
    • stylistically, final variables are always written in all caps.
  • why use constants?

private int x
private final int MAX = 500;
if (x > MAX - x ) { }
    • -there are other uses of final
  • method class
    • inheritance
  • variable
    • constant
  • The constant feature only works with primitives
  • if you declare an object final, that object does not magically become immutable
  • Preconditions and postconditions as the system programmer, you have a contractual relationship with the application programmer.
  • AP calls your methods satisfying conditions which you specify
  • eg. amount >= 0 indeposit(), withdrawal
  • Postcondition:
    • In return, you agree that the method output satisfies given conditions
    • Example: getbalance() returns the correct balance
    • Preconditions dont need to be checked
    • postcondition should be checked during debugging
    • assert checking to ensure postconditions be satisfied
    • pre and postconditions must be specified in javadoc


Anonymous said...

hey guys sorry about this question, but I joined the course recently and I'm in "Section N: Gordon Turpin class" I was wondering if we use the same site "" for both sections or not and do we follow the same lab test dates?

Anonymous said...

yeah its the same for both sections