slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Modular OOP with Units and Mixins PowerPoint Presentation
Download Presentation
Modular OOP with Units and Mixins

Loading in 2 Seconds...

play fullscreen
1 / 50

Modular OOP with Units and Mixins - PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on

Modular OOP with Units and Mixins. Paper by Finder/Flatt Presentation by Dan Licata. Scheme in Fixnum Minutes. > 4 4 >(define x 4) > x 4. Scheme in Fixnum Minutes. >(+ 4 4) 8 > (+ (+ 4 (+ 4 4)) (+ 4 4)) 20. Scheme in Fixnum Minutes. > 5 5. Scheme in Fixnum Minutes.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Modular OOP with Units and Mixins' - salim


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
modular oop with units and mixins

Modular OOP with Units and Mixins

Paper by Finder/Flatt

Presentation by Dan Licata

scheme in fixnum minutes
Scheme in Fixnum Minutes

> 4

4

>(define x 4)

> x

4

scheme in fixnum minutes1
Scheme in Fixnum Minutes

>(+ 4 4)

8

> (+ (+ 4 (+ 4 4)) (+ 4 4))

20

scheme in fixnum minutes3
Scheme in Fixnum Minutes

> (define add2 (lambda (x y) (+ x y)))

> (add2 4 5)

9

> add2

<#procedure...>

scheme in fixnum minutes4
Scheme in Fixnum Minutes

(define add2(lambda (x y) (+ x y))

> (add2 4 5)

9

(define mk-add(lambda (x) (lambda(y) (+ x y))))

scheme in fixnum minutes5
Scheme in Fixnum Minutes

> (mk-add 4)

#<procedure>

> (define add4 (mk-add 4))

> (add4 5)

1

(define mk-add(lambda (x) (lambda(y) (+ x y))))

reading a paper
Reading a Paper
  • What problem are they solving?
  • How do they solve it?
  • Why should I care?
reading a paper1
Reading a Paper
  • What problem are they solving?
  • How do they solve it?
  • Why should I care?
extensibility
Extensibility!

Same story as last time:

  • Functional programming => easy to add a new operation
  • OOP => easy to add a new datatype variant

What would the ideal be?

extensibility1
Extensibility

Shape

Clients

add a new variant
Add a New Variant

Shape

Existing clients should not need to be modified!

Clients

add a new variant1
Add a New Variant

Shape

Clients

New

Clients

add a new operation
Add a New Operation

Shape

Clients

New

Clients

presumptions in the picture
Presumptions in the Picture
  • Add a new operation by subclassing
  • If the change gets used behind the original interface, unmodified clients should see it

In traditional OOP, do they?

define original datatype
Define Original Datatype

(define Shape (interface () draw)

(define Rectangle

(class* null (Shape) (width height)

(public

[draw (lambda (window x y) …))]))

define original datatype1
Define Original Datatype

(define Circle

(class* null (Shape) (radius)

(public

[draw (lambda (window x y) ...))]))

define original datatype2
Define Original Datatype

(define display-shape

(lambda (shape)

(let ([window ...])

(send shape draw window 0 0))))

create a client
Create A Client

(display-shape (make-object Rectangle

50

100))

add a new variant2
Add a New Variant

(define Union

(class* null (Shape) (left right)

(public

[draw (lambda (window x y) ...))]))

add a client that uses it
Add a Client that Uses It

(display-shape

(make-object Union

(make-object Rectangle 10 30)

(make-object Circle 20)))

add a new operation1
Add a New Operation

(define BB-Shape

(interface (shape) bounding-box)

(define BB-Rectangle

(class* Rectangle (BB-Shape) (w h)

(public

[bounding-box (lambda ()

(make-object BB

0 0 w h))])

...))

add a new operation2
Add a New Operation

(define display-shape

(lambda (shape)

(let ([bb (send shape bounding-box)]

(let ([window ...] [x ...] [y ...])

(send shape draw window x y)))))

do the old clients use it
Do the Old Clients Use It?

(display-shape (make-object Rectangle

50

100))

(display-shape

(make-object Union

(make-object Rectangle 10 30)

(make-object Circle 20)))

do the old clients use it1
Do the Old Clients Use It?

(display-shape (make-object Rectangle

50

100))

(display-shape

(make-object Union

(make-object Rectangle 10 30)

(make-object Circle 20)))

potential solution
Potential Solution
  • Always program using Abstract Factory
  • Downsides:
    • Requires forethought
    • Contorts the code

How can we add language support?

reading a paper2
Reading a Paper
  • What problem are they solving?
  • How do they solve it?
  • Why should I care?
fortune cookie wisdom
Fortune-Cookie Wisdom

Every problem in CS can be solved by adding a layer of indirection.

  • Layers:
    • Mixins
    • Units
mixin
Mixin

Class that is parameterized by its superclass

(define BB-Rect

(class* Rectangle ...))

(define BB-Rect

(lambda (Rect)

(class* Rect ...)))

slide31
Unit

Module that is

  • Separately compilable
  • Black-box reusable (has an interface)
  • Multiply instantiable
  • Dynamically linkable
define original datatype3
Define Original Datatype

(define Basic-Shapes

(unit (import)

(export Shape Rectangle Circle)

(define Shape (interface ...))

(define Rectangle (class* ...))

(define Circle (class* ...))))

define original datatype4
Define Original Datatype

(define GUI

(unit (import Shape)

(export display-shape)

(define display-shape ...)))

create a client1
Create a Client

(define Picture

(unit (import Shape Rectangle Circle

display-shape)

(export)

(display-shape

(make-object Rectangle 50 100))))

link them all together
Link Them All Together

(define Basic-Program

(compound-unit

(import)

(link [S (Basic-Shapes)]

[G (GUI (S Shape))]

[P (Picture (S Rectangle)

(S Circle)

(G display-shape))])

(export)))

and run it
And Run It

(invoke-unit Basic-Program)

add a new variant3
Add a New Variant

(define Union-Shape

(unit (import Shape)

(export Union)

(define Union (class* ...))))

package it up with the others
Package It Up with the Others

(define Basic+Union-Shapes

(compound-unit (import)

(link [S (Basic-Shapes)]

[US (Union-Shape (S Shape))])

(export (S Shape) (S Rectangle)

(S Circle) (US Union))))

add a client that uses it1
Add a Client that Uses It

(define Union-Picture

(unit (import Rectangle Circle Union

display-shape)

(export)

(display-shape

(make-object Union

(make-object Rectangle 10 30)

(make-object Circle 20))))

link them all together1
Link Them All Together

(define Union-Program

(compound-unit

(import)

(link [S (Basic+Union-Shapes)]

[G (GUI (S Shape))]

[P (Picture (S Rectangle)

(S Circle)

(G display-shape))]

[UP (Union-Picture (S Rectangle)

(S Circle) (S Union)

(G display-shape))])

(export)))

Picture is

unchanged!

add a new operation3
Add a New Operation

(define BB-Shapes

(unit (import Shape Rectangle Circle Union)

(export BB-Shape BB-Rectangle

BB-Circle BB-Union)

(define BB-Shape (interface ...))

(define BB-Rectangle (class* Rectangle ...))

(define BB-Circle (class* Circle ...)

(define BB-Union (class* Union ...)

(define BB ...)))

Implicit mixin!

package it up with the others1
Package It Up with the Others

(define Basic+Union+BB-Shapes

(compound-unit (import)

(link [S (Basic+Union-Shapes)]

[BS (BB-Shapes (S Shape)

(S Rectangle) (S Circle) (S Union))])

(export (S Shape) (BS BB-Shape) (BS BB)

(BS (BB-Rectangle Rectangle))

...)))

Rename to preserve substitutability!

use the new functionality
Use the New Functionality

(define BB-GUI

(unit (import BB-Shape BB)

(export display-shape)

(define display-shape ...)))

link them all together2
Link Them All Together

Picture and UnionPictureare unchanged!

(define BB-Program

(compound-unit

(import)

(link [S (Basic+Union+BB-Shapes)]

[BG (BB-GUI (S BB-Shape) (S BB))]

[P (Picture (S Rectangle)

(S Circle)

(BG display-shape))]

[UP (Union-Picture (S Rectangle)

(S Circle) (S Union)

(BG display-shape))])

(export)))

reading a paper3
Reading a Paper
  • What problem are they solving?
  • How do they solve it?
  • Why should I care?
solves extensibility problem
Solves Extensibility Problem
  • You can add both new variants and new operations without modifying existing clients
  • Unmodified clients may use the new operation
  • Or, they may not
synergy between modules and classes
Synergy Between Modules and Classes
  • Modules are good for:
    • Separate development
    • Linking
  • Classes are good for:
    • Extensible datatypes
    • Selective reuse
  • Language should have both!
separate definitions and linking
Separate Definitions and Linking
  • Module: externally link dependencies
  • Classs: externally specify superclass

In both, allow substitution of subtypes!

in a statically typed setting
In A Statically-Typed Setting
  • Would this work for Java?
  • Would this work for ML-with-objects?
bigger picture
Bigger Picture
  • Do you buy it?
  • How could it be improved?