se1021-5-1-ActionListener

Download Report

Transcript se1021-5-1-ActionListener

SE-1021
Software Engineering II

Week 5, Class
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
1
Announcement
Johnson Controls CE event
in the Todd Weir Auditorium
on Monday, March 30, 5-7 PM (Spring Quarter)
Direct Supply SE event
Location TBA (but probably Todd Weir Aud.)
Around the same time, but not on the same
day…
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
2
What is an inner class?

An inner class is



Declared inside of another class
Usually declared private (needed by only one
class)
Has access to all variables of the top-level class




Even instance variables!
And so … _____________________________
Even private variables!
And so … ______________________________
Dean & Dean, 2nd Ed. Pp 775-776 (Sec. 17.10)
http://docs.oracle.com/javase/tutorial/java/javaOO/n
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
3
Drawing an inner class on a
UML Diagram
You might think we draw it like this:
Gui
ButtonHandler
But actually, we draw it like _____________
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
4
Drawing an inner class on a
memory-map diagram
You might think we draw it like this
main
myGui
Gui
Gui ref
ButtonHandler
But actually, we will draw it like_____________
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
5
Anonymous Inner Class
This is a class that is DECLARED at the same
place it is INSTANTIATED in the program
Syntax:
new InterfaceName () {
ClassBody
}
Use: Use it where you would use the
constructor of the class
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
6
Lambda Expression
A lambda expression is an anonymous inner
class with shorter syntax, for interfaces with just
one method.
Example:
e -> myMethod(e)
Use: Use it where you would use a constructor
or an anonymous inner class.
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
7
From the Horse’s Mouth*
“Lambda expressions let you express
instances of single-method classes more
compactly.”
http://docs.oracle.com/javase/tutorial/java/java
OO/lambdaexpressions.html (emphasis added)
* “straight from the Horse’s mouth” is an idiom
saying to get something from an authoritative
source. It refers to looking into a horse’s mouth
to determine its age.
SE-2811
Dr. Josiah Yoder
Slide style: Dr. Hornick
8