1 / 23

CSSE221: Software Dev. Honors Day 10

CSSE221: Software Dev. Honors Day 10. Announcements Fifteen due Monday 11:59 pm. Monday will be a workday. Quizzes passed back Sec 2, question 8. Are all events handled by some sort of listener? Questions on GUIs, EventListeners or Fifteen? Fire up Angel and Eclipse now.

wallaces
Download Presentation

CSSE221: Software Dev. Honors Day 10

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. CSSE221: Software Dev. Honors Day 10 • Announcements • Fifteen due Monday 11:59 pm. Monday will be a workday. • Quizzes passed back • Sec 2, question 8. Are all events handled by some sort of listener? • Questions on GUIs, EventListeners or Fifteen? • Fire up Angel and Eclipse now

  2. This week: Fifteen assignment • Monday: • GUIs using Java’s Swing library • Tuesday: • Fifteen specification • EventListeners: responding to user input • Intro to UML as a design tool • Time to work on project • Thursday: • Start prep for round 2 capsules • Anonymous classes (capsule) • Function objects and comparators (capsule)

  3. How to do a capsule?Round 2: +Demo and Activity • I still lecture (15-20 min). • You still create a summary and quiz. • Now, you create the demonstration. • Code that shows a concept. • How will you know if your classmates are understanding it? • Now, you create a hands-on activity for the class, like? • Start the demo code together (like SwingDemo) • Have them extend the demo code (like SalariedEmployee) • Do a kinesthetic activity (like having the class act out a sort method) • Use your creativity!

  4. More about the Demo/Activity • Total time for both: ~25-30 minutes • Integrate your quiz with your demo/activity: • 2-3 questions must relate to them. • Roles of Teammates: • Demo Driver: explains the code and adds any live code • Roving Expert: checks if any students are having difficulties, asks if they need help • Questioner: chooses students to ask the questions on the quiz, asks them, and provides encouragement or corrective feedback as appropriate.

  5. Capsule Deliverables • By 7:30 am on the day you are presenting: • Email the quiz, key, and summary to me (as before) • Commit your demo to csse221-200810-public • Include your section number in the project name: csse221 • Bring to class printed versions (as before): • 1 copy of summary • 2 copies of key • Enough copies of quiz for the class (20)

  6. Choose topic preferences for group 2 • Angel survey in Lessons > Other • 2 minutes

  7. Anonymous Classes • Say I have a really small class that won’t get re-used by other classes. • If I don’t want to write it in its own file, I have 3 options: • Nested classes • Local classes • Anonymous classes

  8. Nested Classes • A class defined within another class. It is only visible to the outer class. • It must be declared static, or else it is an inner class. Inner classes are typically made visible to the world (like Ellipse2D.Double)

  9. Local Classes • Declared inside a method • Their scope is only the method in which they are declared • Not declared private or static. • Have access to local final variables of the method. • Weiss doesn’t use these

  10. Anonymous Inner Classes • A class with no name! • So it can only be used once! • Used to provide a class that implements an interface (or extends a class). • Instead of writing new Inner(), we write new Interface(), then provide the definition of the interface’s methods in curly braces {}. • To extend a class, we provide definitions of the overridden methods • Limitation: can’t specify a constructor

  11. Demo • Check out SwingDemoWithAnonymousClasses • Disconnect • Together, we’ll make the listeners anonymous • Then, 5-minute break

  12. Function Objects (a.k.a. Functors) • Consider sorting an array of objects. • Sorting requires elements can be comparable, such as numbers. • However, what if there were more than one way to compare the elements? • We’d like to be able to tell the sorting function how to compare the elements.

  13. Function Objects (a.k.a. Functors) • We'd like to be able to pass a method as an argument to another method. (what is the role of arguments to methods in general?) • This is not a new or unusual idea. • We frequently pass other functions as arguments to Maple's plot and solve functions .

  14. Function Objects (a.k.a. Functors) • We'd like to be able to pass a method as an argument to another method. • This is not a new or unusual idea. • Maple's plot and solve can take function arguments. • C and C++ provide qsort, whose first argument is a comparison function. • Scheme has sort, which can take a function as its first argument.

  15. Function Objects • What's it all about? • Unfortunately, Java (unlike C++) doesn't allow functions to be passed directly as arguments. • But we can create objects whose only purpose is to pass a function into a method. They are called functionobjects, a.k.a. functors. • Weiss' example: • Uses Comparator objects (interface is defined in java.util.Comparator ). • What is Comparator used for? • Why not just use Comparable? • OrderRectByWidth, SimpleRect, CompareTest

  16. How to pronounce Comparator, Comparable

  17. You can install this Comparator Interface Weiss provides code for several classes that are equivalent to those in java.util, so we can see how parts of the java.util classes might be implemented. • Generics would make this code more complicated; we’ll deal with that later.

  18. Comparator Example part 1 The SimpleRectangle class does not implement Comparable, because there is no one "natural" way to order SimpleRectangle objects.

  19. Comparator Example part 2 Two comparator classes.

  20. Comparator Example part 3 Without something like Comparators, we would need separate findMax functions for finding the max using different comparison criteria • Note that java.util.Collections.max() has similar functionality for ArrayLists and other collections.

  21. Demo • Passing a comparator to a sort method. • Check out the ComparatorDemo project. • Follow the directions on the top of the program.

  22. On HW5… • Weiss 4.29-30 (was 4.28-29 in ed. 2) • Read over now • EqualsK should implement your interface from the first problem. Add extra tests to your main method to create some different equalsK objects and pass them, along with an interesting array, to the countMatches() method. • You can submit (to the drop box for WA2) one set of classes that solves and tests both problems.

  23. Hints • Analogy with the Rectangle example: • countMatches (like findMax) is the method that takes an array and a function object as parameters. • EqualsZero (like findMaxByWidth) is specific function object. • ??? (like Comparator) is the function object interface: you pick the name.

More Related