Frameworks - - PowerPoint PPT Presentation

frameworks
SMART_READER_LITE
LIVE PREVIEW

Frameworks - - PowerPoint PPT Presentation

Frameworks Some material from Ciera Jaspan, Bill


slide-1
SLIDE 1

Frameworks

  • Some material from Ciera Jaspan,

Bill Scherlis, Travis Breaux, and Erich Gamma

slide-2
SLIDE 2

Terminology: Libraries

  • !
  • "#
  • "#

Library

slide-3
SLIDE 3

Terminology: Frameworks

  • $!%!

&

  • $!
  • '
  • $!!
  • $!!
  • "()*+,+-.

Framework

  • But this is an

application! Hey, wasn’t this a library?

slide-4
SLIDE 4

More terms

  • /''/0

!

  • "/
  • '&!
  • '&!
  • 1#!

#'

slide-5
SLIDE 5

More terms

  • "#2

/

  • !'!

&

  • !3

'2' '

slide-6
SLIDE 6

Using an API

  • !'
  • $!
  • 4'#
  • !!

'

slide-7
SLIDE 7

Google’s Map.Reduce

  • ''''

Input key.value pairs Intermediate key.value pairs Output key.value pairs map : (k1,v1) list (k2,v2) reduce : (k2,list(v2)) list (v2)

  • 1#
  • 56%07
  • 507
  • 5087

8 9:

slide-8
SLIDE 8

Google’s Map.Reduce

  • ;

Input key.value pairs Intermediate key.value pairs Output key.value pairs map : (k1,v1) list (k2,v2) reduce : (k2,list(v2)) list (v2)

  • /!<(!<
  • =<
  • <
slide-9
SLIDE 9

Some Benefits of Map.Reduce

  • &
  • >>>0
  • #
  • ''
  • ''
  • '
  • $
slide-10
SLIDE 10

Constraints

  • ? '
  • @%'
  • ='#'

'<

slide-11
SLIDE 11

Hadoop: Map.Reduce in Java

  • AA--'A
slide-12
SLIDE 12

: An Eclipse Plugin

  • B /*1
  • @'0!

)'0' ''-.

  • '!8C/
  • '@
  • '

@4->

  • @1'

@1,:

  • >->

'--0 '---0 '--3-#0

$!

  • D>>EB
  • @

'--3-#0 '--- &

  • B 1-F
slide-13
SLIDE 13

: An Eclipse Plugin

  • '-#
  • @'
  • G@
  • #
  • 1#
  • #

'---

  • #

H<# :I->I':I6"$JI<K H< :IL-I<K H'K H# :I'---IK H :IG@1I #:I#I

$! L

  • D>>EB
  • #
  • 2
  • '#

0-M

#:I#I :IA-') :I'---#-N "#1I :I--G@1I :I--G@1IK HAK HA#K HA'K

slide-14
SLIDE 14

: An Eclipse Plugin

  • 0M
  • G@1-3
  • /"#1
  • 00 000

AA0A0O

  • %1P?/1
  • N /"#1
  • !"

$!

  • D>>EB
  • 1##'''
  • G@*

'

  • G@'
  • !"

" #$% #$% &

  • &

&

slide-15
SLIDE 15

: a JUnit Plugin

public class SampleTest { private List<String> emptyList; @Before public void setUp() { emptyList = new ArrayList<String>(); } @After public void tearDown() {

Here the important plugin mechanism is Java annotations

$!

  • D>>EB

public void tearDown() { emptyList = null; } @Test public void testEmptyList() { assertEquals("Empty list should have 0 elements", 0, emptyList.size()); } }

slide-16
SLIDE 16

The Golden Rule of Framework Design

  • 1#'!?8"2'

!M

  • *#<
  • 570'0!
  • $!570'
  • $!570'
  • 1-'-''

:-'57-5'Q>R7, ':-/57,

  • $!!'
  • 'B%
slide-17
SLIDE 17

Java Swing: It’s a Library!

  • C6/'
  • B$0B0B*'0B@N
  • 6''&
  • B0B"#$0BN

"$/A8M

slide-18
SLIDE 18

Swing: Containers and Components

  • !"
  • #

$#$%& #

Enter your userid:

slide-19
SLIDE 19

Swing: Layout Managers

'() '()*'()* ( ( *+,-" #'()*./012/34 #'()*./012/34 )5# 6 )% )7 6 )%5 8 '()*9: 15;5;)

slide-20
SLIDE 20

Swing: Events

6 , 4 , , 4< =6 *+, =< :6> +6-" ? :6> +6-" ? @)-" A A

But this extending a class to add custom behaviors, right?

slide-21
SLIDE 21

Where is the boundary?

  • MouseAdapter

AWT Framework Swing

  • JPanel

JButton $1

Swing Framework Our Implementation

MyWidget

slide-22
SLIDE 22

Swing: Custom Components (Reuse)

,9)< ,9)6< '() '()*'()* B

  • #

A =66< ) A A

slide-23
SLIDE 23

Swing: Custom Components

,9)*< ,9)6< ) A 6#=8) 6#=8) =*6')< 6 @6):8 )** )055)9 ).) A A

slide-24
SLIDE 24

OO Frameworks (credit: Erich Gamma)

  • &'

'

  • !
  • 3

framework application

  • %
  • '
  • $!

'

class library

reusing a framework

slide-25
SLIDE 25

Framework Challenges (credit: Erich Gamma)

  • !
  • !'
  • )! 3.
  • '

) !" . *

  • 0! !#M
slide-26
SLIDE 26

Framework Layering (credit: Erich Gamma)

  • Defaults/Standard Package
  • reuse of design and code

Framework Package

  • reuse of design
  • stable

→ no implementation

  • specifies public interfaces

more con more sta

F

StandardDrawing

  • LineConnection
  • reuse of design and code
  • less stable

→ more implementation

  • specifies protected interfaces

Kit Packages

  • reuse of implementation
  • least stable

→ implementation only

re concrete re stable

slide-27
SLIDE 27

Evolution: Extract Interface from Class

(credit: Erich Gamma)

⇒B(*!

  • #' '

S D>>EB

  • M
slide-28
SLIDE 28

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

  • J

D>>EB

  • !"
slide-29
SLIDE 29
  • #$
  • %
  • #$ &!

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

E D>>EB

  • !"
slide-30
SLIDE 30
  • #$
  • %
  • #$ &!
  • %'

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

L> D>>EB

  • !"

%'

  • '
slide-31
SLIDE 31
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

L D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

slide-32
SLIDE 32
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

L D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

  • )
slide-33
SLIDE 33
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

LL D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

  • )

* *

slide-34
SLIDE 34
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

  • $

$%

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

L D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

  • )

* *

slide-35
SLIDE 35
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

  • $

$%

  • &$

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

L D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

  • )

* * &$

slide-36
SLIDE 36
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

  • $

$%

  • &$

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

LF D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

  • )

* * &$

  • $'
slide-37
SLIDE 37
  • #$
  • %
  • #$ &!
  • %'

$( $ %(

  • $

$%

  • &$

JHotDraw: Design Patterns Summary

(credit: Erich Gamma)

LS D>>EB

  • !"

%'

  • '
  • '

!"'

  • $(

$ %(

  • )

* * &$

  • $'

+! +! "

slide-38
SLIDE 38

JHotDraw Pattern Experiences

(credit: Erich Gamma)

  • /'
  • '
  • /+
  • '
  • !'M
  • $!

LJ D>>EB

  • $!
  • '''
  • B *
  • 3 6%
  • 6%
  • B(*AA'-A3A3
slide-39
SLIDE 39

Getting up a framework’s learning curve

  • "'!
  • "0=&01#
  • $'0C'
  • T
  • 1-'
  • C!'
  • =!0A'
  • !$
  • #T

).

  • Library

Framework

$! LE

  • D>>EB

).

  • /
  • /507
  • "'0!
  • /'
  • N+
  • T !3!
  • *'T )!.
  • $!'+# -
slide-40
SLIDE 40

Framework Design Exercises

  • "!!
  • 4'
  • 4'0'0'
  • '
  • /''
  • @'
  • @'
  • ;
  • = A#<
  • =<
  • =<
  • (!<
slide-41
SLIDE 41

Bonus slides on Frameworks

slide-42
SLIDE 42
  • >'!

Callback challenges

  • -?1"'
  • * '
  • (
  • 1
  • 1
  • 1*6
  • *=B
  • >'!
  • @#
  • =<
  • =/<
  • =!

#<

  • *=B
  • *6
  • :=:*6
  • *
slide-43
SLIDE 43

Dynamically add a control to the page

private void Page_Load(object sender, EventArgs e) { DropDownList ddl = new DropDownList(); ddl.DataSource = H; //accesses another control ddl.DataBind(); addControl(ddl); }

=M% 0 +-

slide-44
SLIDE 44

Dynamically add a control to the page, attempt 2

private void Page_Load(object sender, EventArgs e) { if (!IsPostBack()) { DropDownList ddl = new DropDownList(); ddl.DataSource = H; //accesses another control ddl.DataBind(); addControl(ddl); } }

8!0 '5!7O-

slide-45
SLIDE 45

Dynamically add a control to the page, attempt 3

private void Page_Load(object sender, EventArgs e) { DropDownList ddl = new DropDownList(); if (!IsPostBack()) { ddl.DataSource = H; ddl.DataBind(); } addControl(ddl); addControl(ddl); }

8!00+ AO-

slide-46
SLIDE 46

Dynamically add a control to the page, attempt 4

private void Page_PreInit(object sender, EventArgs e) { DropDownList ddl = new DropDownList(); if (!IsPostBack()) { ddl.DataSource = H; //accesses another control ddl.DataBind(); } addControl(ddl); addControl(ddl); }

?'# '+O

slide-47
SLIDE 47

Dynamically add a control to the page, attempt 5

DropDownList ddl; private void Page_PreInit(object sender, EventArgs e) { ddl = new DropDownList(); addControl(ddl); } private void Page_Load(object sender, EventArgs e) { private void Page_Load(object sender, EventArgs e) { if (!IsPostBack()) { ddl.DataSource = H; //accesses another control ddl.DataBind(); } }

$!M

slide-48
SLIDE 48

Couldn’t they design it better?

  • !
  • N!#
  • /0'

'

  • N'
  • N'
  • ' +
  • N'20!
slide-49
SLIDE 49

Interaction is not limited to your primary code!

  • @'!
  • * 0G@
  • /0/

<

  • '<
slide-50
SLIDE 50

Choosing an interaction

  • 1#/&
  • <
  • 1#"
  • G@00<
  • 1#L*6%
  • 1#L*6%
  • G@000<
  • ?

0'0 'M

slide-51
SLIDE 51

Putting controls in a LoginView

''

  • 1# -)=0

6M.

<asp:LoginView ID=“LoginScreen” runat=“server”> <AnonymousTemplate> <AnonymousTemplate> You can only setup accounts when you are logged in. </AnonymousTemplate> <LoggedInTemplate> <h4>Location</h4> <asp:DropDownList ID=“LocationList” runat=“server”/> <asp:Button ID=“ChangeButton” runat=“server” Text=“Change”/> </LoggedInTemplate> </asp:LoginView>

slide-52
SLIDE 52

Retrieve controls and set them up

LoginView LoginScreen; private void Page_Load(object sender, EventArgs e) { DropDownList list = (DropDownList) LoginScreen.FindControl(“LocationList”); list.DataSource = H; list.DataSource = H; list.DataBind(); }

?%1#-*:O,

slide-53
SLIDE 53

Correct code

LoginView LoginScreen; private void Page_Load(object sender, EventArgs e) { if (this.getRequest().IsAuthenticated()) { DropDownList list = (DropDownList) LoginScreen.FindControl(“LocationList”); list.DataSource = H; list.DataBind(); list.DataBind(); } }

slide-54
SLIDE 54

These sound tough to useHwhy bother?

  • 1!U0>>>0>>>
  • 1'
  • O!
  • @
  • 1#'!'
  • 1#
  • '57
  • N2
slide-55
SLIDE 55

Frameworks and Quality Attributes

  • ;
  • V
  • ;+
  • 8!2
  • ?12!
  • @ 0'
  • (' 0'
  • =!!;
  • "2O
slide-56
SLIDE 56

Choosing a framework

  • N3
  • 1#'!
  • 2
  • '
  • '
  • 5

'7

slide-57
SLIDE 57

Do we build it ourselves?

  • 8'!
  • 1#10B110-?0
  • N!0'0
  • A!
  • /'!
  • /'!
  • 1#!
  • N0
  • A!'02#