Take attendance, hand out syllabus and Java syntax.
Also interested in analyzing how well a program works - efficiency and correctness.
Introduce new ideas in programming language support for problem solving:
Programming language characteristics needed to support this:
Style very important. Readable software necessary for correctness, optimization, and maintainability.
Data and operations are tightly intertwined.
Idea of Abstract Data Types (ADT) - create your own data types with powerful operations.
All the user has to know is what is effect of operations, not how they are done.
E.g. - Data base is good example - representation hidden, but operations available to you.
Objects bundled with their operations (methods)
Ask object to perform
action (send message) - it responsible for knowing how.
Write post-its in Java
Use preconditions and postconditions to specify what actual procedures and functions do (as opposed to how they do it).
If create powerful types of objects with methods at beginning then actual program is easy. This is our goal.
Keep sketchy lecture notes on-line on web page and in CS136 folder of Cider Press.
An object consists of collection of features
Interfaces behave like the types of objects.
Provide
specification (type info) of methods (but not bodies).
Interface EmployeeSpec GetName(): String GetWkPay(): Integer Class Employee Implements EmployeeSpec Instance variables name: string birthDate: date Constructor Employee(emp_name: string; emp_bday: date) // Constructor of objects name <-- emp_name; birthDate <-- emp_bday; Methods GetName(): string return name getAge(): integer return (Today - birthDate) getWkPay(): real return 0.0
If boss represents an object of class Employee, then can write:
boss.getName()to send message to boss to return his/her name.
Inheritance is used to define new classes from old ones (incremental modification) by defining subclasses of existing classes:
Class HourlyEmployee Superclass Employee Instance variables hourlySalary: real Constructor HourlyEmployee(empName: string; empBDay: date; hrlyPay: real) name <-- empName; birthDate <-- empBDay; hourlySalary <-- hrlyPay; Methods setHourlyPay(newSalary : real) hourlySalary <-- newSalary getWkPay: real return (hourlySalary * 40){Note have over-ridden old getWkPay, but getName & getAge as above}
Class ExemptEmployee Superclass Employee Instance variables yearlySalary: real Constructor ExemptEmployee(empName: string; empBDay: date; yrlyPay: real) name <-- empName; birthDate <-- empBDay; yearlySalary<-- yrlyPay; Methods setAnnualPay(salary : real) yearlySalary <-- new_salary getWkPay(): real return (yearlySalary / 52)
Objects in subclass treated as though elements of class as well! If subclass does not provide method to respond to message, then use appropriate one from superclass (or its superclass, etc.)
In particular, subclasses also implement any interface declared for superclass.
Note that same method name can exist in different classes - form of polymorphism.
An hourly employee will respond differently from an exempt employee when getWkPay message is sent.
When want to add a new kind of employee, simply add a new subclass of Employee and only provide routines which differ from those of Employee.