Download presentation
Presentation is loading. Please wait.
Published byShawn Eaton Modified over 9 years ago
1
CSCI 62 Data Structures Dr. Joshua Stough September 9, 2008
2
Today Object-oriented design Interface Assert Generics Program 1.
3
OO Data Abstraction and Encapsulation –cars, toasters, lightbulbs, Strings... –interface – important to the user –implementation – details hidden from user –A fixed interface allows alternative implementations. Maximize efficiency, minimize errors –Hitchhiker’s Guide
4
Concerning the development of fire: The girl in charge of fire development said “When you’ve been in marketing as long as I have you’ll know that before any new product can be developed it has to be properly researched. We’ve got to find out what people want from fire, how they relate to it, what sort of image it has for them. “Stick it up your nose,” Ford said. “Which is precisely the sort of thing we need to know. Do people want fire that can be fitted nasally?”
5
Concerning developing the wheel: “We’re having a little difficulty there.” “Difficulty?” exclaimed Ford. “Difficulty? What do you mean, difficulty? It’s the single simplest machine in the entire Universe!” The marketing girl soured him with a look. “All right, Mr. Wiseguy,” she said, “you’re so clever, you tell us what color it should be.”
6
OO Object Model –class – defines objects of the class type. –object – instance of a class. –Object – all non-primitive objects extend Object. implements toString, equals –An object manages it own data constructor, accessor and mutator methods comprise the interface. Example: cannot change the key/account in a(n) Association/BankAccount –package – collection of related classes (ideally). We’ve seen –Ratio –BankAccount –TextCoinStrip (soon)
7
OO public – everyone has access, protected – children (subclasses), via extends, have access, private – only the instance has access. Overloading – same name, different parameter list Overriding – same name/parameter list, child class.
8
OO – WordList Example No implementation details needed to use the WordList A way to think about it: –Write/think about the pseudocode that uses the object BEFORE implementing the object. –HangMan before WordList –Can be iterative – you start coding in more detail and determine additional functionality.
9
Interfaces public interface ClassName A class can implement an interface –The class must implement all of the interface’s methods
10
Assert Firecrackers in the code Defined in the structure5 package (bailey.jar). void pre(boolean test, String message) Can be placed in any method
11
Generics Recognize errors sooner rather later. generic – class parameterized by the type of data. Java tutorial, generics example. Vector, or Vector Class def.: public class Association Instantiation: Association personAttribute = new Assocation ("Age",34); autoboxed type parameters
12
Program 1 TextCoinStrip –How did you do it? GraphicsCoinStrip –Make functional Instantiate the strip, place a coin Comment out the void method bodies –Add some functionality mousePressed should carry the coin mouseReleased should put the coin back.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.