-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path11-interface-proposal.rkt
executable file
·96 lines (70 loc) · 2.56 KB
/
11-interface-proposal.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;; Here's a proposal for talking about interfaces.
;; A class has two interfaces:
;; -- the methods it provides (perhaps with the help of its
;; superclasses)
;; -- the methods it requires (from its subclasses).
;; Unfortunately, the Racket object system only allows us to document
;; the former; the latter is implicit in the list of (abstract ..)
;; declarations in the superclass.
;; The concept is that the superclass provides services to its
;; subclasses; only the instantiable subclass provides the full interface.
;; Under this plan, the superclass wouldn't claim to implement
;; SBall<%>; only the instantiable subclasses do so.
;; Need to change L11.2 slide 10 to remove (abstract add-to-scene).
;; L11.2 slide 17 needs to change to reflect the new interface.
;; note that add-to-scene is in SBall<%> but not in DWprovides<%>
(define DWprovides<%>
(interface ()
update-wall-pos
after-tick
after-button-down
after-button-up
after-drag))
(define DWHooks<%>
(interface ()
next-x-pos
next-speed
in-this?))
(define DraggableWidget%
(class* object% (DWprovides%)
(abstract
next-x-pos
next-speed
in-this?)
(define/public (update-wall-pos n) ...)
(define/public (after-tick)
(if selected?
this
(let ((x1 (send this next-x-pos))
(speed1 (send this next-speed)))
...)))
;; to be supplied by each subclass
(abstract next-x-pos)
(abstract next-speed)
; NOT an abstract method of this class
; (abstract add-to-scene)
; after-button-down : Integer Integer -> Void
(define/public (after-button-down mx my)
(if (send this in-this? mx my) ...))
;; to be supplied by the subclass
(abstract in-this?)
; after-button-up : Integer Integer -> Void
(define/public (after-button-up mx my)
(if (send this in-this? mx my) ...))
; after-drag : Integer Integer -> Void
(define/public (after-drag mx my) ...)
))
(define Ball%
(class*
;; inherit method implementations from DraggableWidget%
DraggableWidget%
;; all the methods of SBall<%> are either inherited from
;; DraggableWidget% or defined locally.
;; Since we inherit from DraggableWidget%, we need to provide its
;; hooks
(SBall<%> DWHooks<%>)
(define/public (add-to-scene ...) ...)
(define/override (next-x-pos) ...)
(define/override (next-speed) ...)
(define/override (in-this? other-x other-y) ...)
))