20100831

Table of Contents

INFS 519

  • Review Syllabus
  • Office hours by appointment
  • Assignments will be posted to the course website

Review expected knowledge

  • Course will primarily use Java for examples and all programming assignments will be written in Java.
  • Has everyone written Java programs before?
  • Is everyone familiar with classes and OOP?
  • Has everyone used a debugger?

Specification, Design, Implementation

  • See Main Ch 1
  • "A collection of data organized so that items can be stored and retrieved by some fixed techniques."

Phases of Software Development

  • Specification of the task
  • Design of a solution
  • Implementation of solution
  • Analysis of solution
  • Testing and debugging
  • Maintenance and evolution of system
  • Obsolescence

What phases are really like

  1. Identify a problem to be solved
  2. Sketch out a design on paper or with code snippets
  3. Grow code snippets into working components that fit the larger program
  4. Test this code as you are developing it!
  5. Repeat 2-4 until you have a working program
  6. Release!
  7. Maintenance; need to make changes, go back to step 2
  8. Follow the SUN

Design Techniques

Decomposition
Recursively break a problem into smaller problems
Reuse
Solutions to smaller problems are frequently useful in many programs, reuse them!
Avoid leaky abstractions
(This is information hiding.) The caller of your code should not need to know details about your implementation.

Preconditions and Postconditions

A precondition states what things are expected to be true before the function is executed.

A postcondition states what things will should be true when the function has returned, given the preconditions were satisfied.

In Java, documentation can include these and code enforces them. Some other languages actually include them in the language specification.

To alert a user that a precondition was not met, a method can throw an exception.

Review conversion program (p12) to ensure all students understand all syntax

Testing

  • Most languages have at least one good unit testing library. Use them for testing.
  • Preconditions and postconditions are what you will be testing.
  • You can also test that a function fails as you designed if a precondition is violated.

Classes & Packages

  • Classes define data types.
  • Packages keep classes organized.

Packages

  • Packages serve as a namespace in which classes are defined.
  • Packages also guide how you layout your source code on the filesystem.

E.g., a package edu.gmu.cs.ml with a source file BayesianNetwork.java would be stored on the filesystem as \/edu\/gmu\/cs\/ml\/BayesianNetwork.java

The BayesianNetwork.java source file will declare its containing package at the top of the file as: package edu.gmu.cs.ml;

  • Packages can be referenced and used to import classes defined in that package

E.g., in a source file Skynet.java, we might put this at the top of the file: import edu.gmu.cs.ml.BayesianNetwork;

It's also possible to import all classes defined in a package, but this is frequently a bad idea as it can lead to confusion since the classes you are importing are not explicitly listed.

  • If a class member's is not declared with an access modifier, it is considered to have default access. This permits other classes in the same package access to the member.

Classes

  • Abstract data types (ADTs) are models of data structures with corresponding behaviors without specifying the implementation.
  • ADTs usually refer to general data types, such as lists, stacks, queues, etc. But all of these may be implemented as classes. As we'll see later, abstract base classes in Java resemble ADTs closely.
  • Classes define a specification.
  • Instances of a class are created using a constructor.

Class members

There are several types of members that can be defined in a class.

  • Instance variables
  • Class variables
  • Constructors
  • Class Methods
    • perform a utility
      • conversion
      • factory
      • other functionality that does not require a class instance
  • Instance Methods
    • that mutate (Modification Method)
    • that observe (Accessor Method)
    • or both!
  • Review Throttle.java to point out different members and their characteristics.
  • It's idiomatic Java to use getters and setters to get or set member variables. Other OOP languages may generate these methods for you or encourage direct access to variables.
  • Methods can call other methods.
  • Constructors don't return a result, they are initializing a new instance of the class.

Runtime Analysis

  • How long does the algorithm run?
    • Based on the input size.

Counting stairs

  1. Walk down and keep count
  2. Walk down but let someone else keep count
  3. Ask someone that knows

Number of operations

  1. 3n
    • Make n marks, go down n stairs, go back up n stairs
  2. n + 2 (1 + 2 + … + n)
    • Go down to a step, run back and report it, return to the step and go down one more plus n marks made total.
  3. 4
    • Write down a representation of the number given to you by someone that has already counted the stairs.

Runtimes

  1. 3n
  2. n2 + 2n
  3. floor(log10 * n) + 1

In Big-O notation

  1. O(n)
    • linear
  2. O(n2)
    • quadratic
  3. O(log n)
    • logarithmic

HTML generated by org-mode 6.35i in emacs 23