Object Oriented Programming and Design in Java
Session 12 Instructor: Bert Huang
Object Oriented Programming and Design in Java Session 12 - - PowerPoint PPT Presentation
Object Oriented Programming and Design in Java Session 12 Instructor: Bert Huang Announcements Midterm exam Wednesday, Mar. 10 th Midterm sample problems and solutions posted on courseworks Review Java Types Arrays, enums
Session 12 Instructor: Bert Huang
contract
in use cases. Then...
talk to user or other programs
ClassName responsibility 1 responsibility 2 ... Collaborator 1 Collaborator 2 ...
Class Name Attributes : Type Methods
instances
Class
Class doSomething()
Type in all caps Type in lowercase hit caps lock hit caps lock
MyClass int data String name OtherClass thing void doSomething() int getSomething()
The rest of your program...
/* interface methods */
BufferedReader(new InputStreamReader(System.in))
accurately
user can affect via GUI
view and a controller
updates
Model Stores text and formatting markup (fonts, sizes, colors) Notifies View to update when Model changes View Displays text with proper fonts and sizes Displays toolbar Notifies Controller when user edits text or clicks toolbar commands Controller Notifies model to change text when user inputs Notifies model to perform special commands when toolbar buttons are clicked
event occurs
composite class applies method to its primitive objects and combines the results
plain component
decoration
algorithm
custom versions of the algorithm
the algorithm
algorithm
context class
class calls the appropriate methods of the strategy object
classes in which a subclass is a more specific form of a superclass
methods and fields
methods
to superclass
including constructor
true for objects y of type S where S is a subtype of T. (Liskov)
whenever a superclass object is expected
confusion if we're unclear on how inheritance works
MyMouseListener
ma.mouseClicked(); // what happens?
determine which methods are called
subclasses
private methods
interchangeable, since subclasses would depend
functionality using only public interface of superclass
preconditions than superclass methods
postconditions than superclass methods
Liskov substitution; they must be viewable as superclass objects
The primitive operations can be different for each type
depend on the type
algorithm and abstract methods for the primitive algorithms
algorithm
variables into types
whole story
compiler checks to validate type usage