Overview and Preliminaries
Why Software Design (Java)?
Java is an ideal object-oriented language(?)
- Java is a "pure" object-oriented language (almost)
- "simple, dynamic, and secure.."
- pretty cool: web-oriented, portable, concurrent, etc.
However, the use of Java is not at all simple:
- many non-trivial features: classes and polymorphism combined with
procedural mechanisms (primitive types, static
properties,
inner (static/anonymous) classes, exceptions)
- huge class libraries
- in API 1.0: 212 classes and 2125
methods,
in Standard Edition (SE) API 1.4,
3020 classes and 32138 methods
- most of Java is in its libraries; you need to know and understand
Java class libraries
to really do something useful in Java
- how to write reusable and robust code, use and build
frameworks and components?
- need to master general object-oriented design patterns to
understand
existing class libraries and to write new ones
-
Iterator, Composite, Strategy,
Observer, Proxy,
Template Method, Bridge, etc.
- master language-specific idioms and antipatterns
- idioms for compareTo, equals,
hashCode, toString, clone,
type-safe enum classes, exception chaining, etc.
- antipatterns such as unsynchronized concurrent access,
busy-wait, failing double-check idiom,
int enum values, using
null for zero-length arrays, etc.
- Java language features are in principle "secure"
(type-safe)
- but Java programs are not necessarily safe:
- run-time errors and exceptions: how to prevent and/or handle?
- built-in error detection works only for language features
(index check)
- how to detect higher-level data corruption and invariant
violations?
- how to recover from failures and errors?
- techniques and tools
- defensive programming and
programming-by-contract
- pre- and post-conditions
- assert facility
- to inspect and find out about program you must make its
behaviour visible and observable:
must use debugging and logging
- some aspects of Java are not even in principle portable:
- nondeterministic threads: scheduling, deadlocks/starvation, etc.
- also: non-strict (machine-dependent) floating-point
calculations
-