Object Oriented Programming and Design in Java
Session 21 Instructor: Bert Huang
Object Oriented Programming and Design in Java Session 21 - - PowerPoint PPT Presentation
Object Oriented Programming and Design in Java Session 21 Instructor: Bert Huang Announcements Homework 4 due now Homework 5 out now. Due last day of class: Mon. May 3rd Mon. May 3rd: Final review Mon. May 10th, Final exam. 9
Session 21 Instructor: Bert Huang
material, but material is inherently cumulative
insert findMin get
get range
lists hashmap BST heap
O(1) O(N) O(N) O(N) O(1) O(N) O(1) O(N) O(log N) O(log N) O(log N)
O(log N + k) k = # elements in
range
O(log N) O(1) O(N) O(N)
assign priority to all requests
element
application
prioritization and just do it fast
extremely fast, thread safety is omitted to avoid overhead
implemented by ConcurrentHashMap
implemented by ArrayBlockingQueue, LinkedBlockingQueue
Collection synchronizedCollection(Collection c)
MVC COMPOSITE DECORATOR STRATEGY TEMPLATE-METHOD ADAPTER COMMAND FACTORY-METHOD PROXY SINGLETON VISITOR
interfaces that do the same thing
names, parameter order, etc
classes, create an adapter
the other
modifying it.
requires conformance to a target interface
conceptually related
interface
It translates target methods to adaptee methods
/** An adapter that turns an icon into a JComponent. */ public class IconAdapter extends JComponent { /** Constructs a JComponent that displays a given icon. @param icon the icon to display */ public IconAdapter(Icon icon) { this.icon = icon; } public void paintComponent(Graphics g) { icon.paintIcon(this, g, 0, 0); } public Dimension getPreferredSize() { return new Dimension(icon.getIconWidth(), icon.getIconHeight()); } private Icon icon; }
commands,
a method to execute the command
manipulate the state of command objects
command interface type
implementation of a Command interface
method
pop().undo() to undo most recent command
Iterator iter = new LinkedListIterator(list)
kinds of product objects
creators
products
method yields a product object
so that it returns an object of a concrete product class
way
pattern
specified by an subject interface type
make it more versatile
affected by the modification
interface type. The proxy holds a reference to the real subject
real subject and provides the necessary modifications
JLabel label = new JLabel(new ImageIcon(imageName))
time
(imageName))
public void paintIcon(Component c, Graphics g, int x, int y) { if (image == null) image = new ImageIcon(name); image.paintIcon(c, g, x, y); }
more than one instance
interface, can't be passed as a parameter
Random objects; I really only need one
public class SingleRandom { private SingleRandom() { generator = new Random(); } public void setSeed(int seed) { generator.setSeed(seed); } public int nextInt() { return generator.nextInt(); } public static SingleRandom getInstance() { return instance; } private Random generator; private static SingleRandom instance = new SingleRandom(); }
types, and you want to carry out operations that depend on the object types
elements of each of the given types
the matching element visitation method on the visitor parameter
the visitor interface type and supplies the operation's action for each element type
code very general
based on type of element
based on type of Visitor
MVC COMPOSITE DECORATOR STRATEGY TEMPLATE-METHOD ADAPTER COMMAND FACTORY-METHOD PROXY SINGLETON VISITOR