1 / 17

Midterm Review, Assignments 3,4

Midterm Review, Assignments 3,4. Mon: Midterm. Wed: Guest Speaker Michael Pieck, VP Goldman, Sachs & Co. Review for Midterm. Remember IBooleanCriteria?. Interface used to build up boolean statements public boolean satisfies( Object o ) Functor Use this to filter

josborne
Download Presentation

Midterm Review, Assignments 3,4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Midterm Review, Assignments 3,4

  2. Mon: Midterm Wed: Guest Speaker Michael Pieck, VP Goldman, Sachs & Co

  3. Review for Midterm

  4. Remember IBooleanCriteria? • Interface used to build up boolean statements • public boolean satisfies( Object o ) • Functor • Use this to filter • FilteredIterator goes with it List l = … new FilteredIterator( l.iteratior(), booleanCriteria() )

  5. What does this do myClass.newInstance() • Creates new instance of Class called myClass • You have to have no arg constructor) • Ctor needs to be public

  6. Remember Factory Method? • Class that instantiates objects of different types based on keys.

  7. Remember is Singleton? • Class that allows only one instance • Private constructor • Either public static accessor method or • Public static instance

  8. Remember Observable/Observable? • Its pattern which is applicable to cases when objects need to be aware of the state change in other objects • Observable always maintains a list of observers and notifies them when changes occur by either specific method or via an event

  9. Remember Cache? • Class or collaboration or pattern which allows faster access to a subset of data, which is typically most often used. • Speed of search • What to evict? • Evict the oldest ones • Random • Least frequently accessed

  10. What does this do? List l = new ArrayList(); for ( int i = 0; i < 10; I++ ) { l.add( createRandomShape() ); } Iterator iter = new FilteredIterator( l.iterator(), new IBooleanCriteria() { public boolean satisfies( Object o ) { return ( o instanceof Circle ); } } ); while ( iter.hasNext() ) { System.out.println( o.next() ); }

  11. Remember Object Pool? • Pattern where N objects are typically allocated instead of 1 and then reused. • Object get() • Release( Object o )

  12. Remember Uses, Contains, Extends? Public class MyClass extends YourClass { // uses Public Foo add( Bar b ) { A a = new A(); b.doSomethig(); } // contains private XYZ xyz; }

  13. Remember Comparator and Comparable? • Comparable: compareTo( Object o ); • Comparator: int compare( Object o1, Object o2 ) • Comparable is interface implemented by objects with natural ordering • Comparator is an interface used to compare any two objects

  14. Pulic class StudentFirstNameComp implements Comparator { Public int compare( Object o1, Object o2 ) { Return ((Student)o1).getFirstName().compareTo( ((Student)o2).getFirstName() ); } List l = createListOfStudents(); Collections.sort( l, new StudentFirstNameComp () ); Collections.sort( l );

  15. Remember Flyweight? • Only one instance of every flyweight exists by is created dynamically. Flyweights are immutable. • ColorFactory { • public Color getColor( int r, int g, int b ); • }

  16. <eworld class=EWorld> <property name=mutation value=0.0001/> <site class=Desert> <property name=bg value=red/> </site> </eworld> public class Eworld { public void addSite( ISite site ) public void setMutation(); public double getMutation(); } public class Desert impl ISite { public void setBg(); public Color getBg(); }

  17. // build for site tag • Public void build( ITag parent ) { • super.build( parent ); Eworld ew = (Eworld)parent.getObject(); Isite site = (Isite)getObject(); ew.addSite( site ); }

More Related