CS 448 Lecture - Java abstraction
Topics for today:
- Reading
- C9, C10: The "replicator"; panspermia. Time scales. Aside; things are not always simple, e.g. sweat glands.
Culture as adaptive/evolving; memes (ideas are like viruses)
- Samuel - design for minimax code
- Lab due date extended *again*!?! Yes, 'til Tues... but with bonus for already demo'd
- Interface in Java
- An interface is just a list of signatures of methods a class must, uh, implement in order to implement that interface
- Helps write generic code
- Collections.sort(ArrayList<String>)
- Implementing Comparable with Strings inside a class
- Implementing Comparable with ints inside a class
- Facilitates team programming
- Example: robot cars. Agree on the Driveable interface, then one person can write the driver and the other can implement Driveable
- Allows decoupling
- Each side (of the interface) can develop/test independently
- Designing a Driveable interface
- input devices - camera, sonar, GPS
- output devices - brake, throttle (both boolean!), steering (can adjust by +left or +right)
- Addresses the lack of multiple inheritance in Java
- Parameter types may be interfaces!
- Abstract classes in Java
- Makes it possible to abstract commonalities from two (or more) classes.
- Like interface, makes it possible to require certain methods to be implemented. Each signature is preceded by abstract; each must be overridden in subclasses (which
are not themselves abstract).
- Methods may be implemented in the abstract class; if they are not overridden in a subclass when sent to the subclass object the superclass method is executed.
- Can declare variables in abstract classes
- Cannot instantiate!
- Classes may only extend one other class
- Parameter types may be abstract