Please...help...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Please...help...

hjmma
I'm also implementing decorator in smalltalk. I would like to do a ScollBar
and a Border decorator for a textView...like in "DESIGN PATTERNS - ELEMENTS
OF REUSABLE OBJECT-ORIENTED SOFTWARE" book by "E. GAMMA, R. Helm...". In
this book there is exactly the particular case i would like to implement
wich i mentioned before. I've done the "VisualComponent" class with void
implementation (subclassResponsibility), the "Decorator" 'interface' wich
subclasses "VisualComponent", "ScrollDecorator" and "BorderDecorator" wich
subclass "Decorator". I'v given an half-implementation because i really
don't where i've to put this classes in the Dolphin Hierarchy...My hierarchy
is DECORATOR PATTERN hierarchy:

VisualComponent
                Decorator
                        ScrollDecorator
                        BorderDecorator
                TextView

Do I have to construct some resources to view a border over a scrollbar over
a textview? How may i to combine my classes hyerarchy (wich respects
Decorator PATTERN structure) in Dolphin Hierarchy to view a textview with
scrollBars? What Are the instruction in SmallTalk that i've to put in "draw"
message to really view  the textView and the decorators?

Here my code:
===========

"Filed out from Dolphin Smalltalk 2000 release 4.01"!

Object subclass: #VisualComponent
 instanceVariableNames: ''
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
VisualComponent comment: ''!

VisualComponent guid: (GUID fromString:
'{6C120F01-F0B4-11D5-8488-00D059066040}')!

!VisualComponent categoriesForClass!Unclassified! !
!VisualComponent methodsFor!

draw
^self subclassResponsibility!

x: xd y: yd
^self subclassResponsibility! !
!VisualComponent categoriesFor: #draw!*-subclass
responsibility!drawing!public! !
!VisualComponent categoriesFor: #x:y:!*-subclass
responsibility!accessing!public! !
-------------------------------
"Filed out from Dolphin Smalltalk 2000 release 4.01"!

VisualComponent subclass: #Decorator
 instanceVariableNames: 'vcobj x y'
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
Decorator comment: ''!

Decorator guid: (GUID fromString: '{6C120F02-F0B4-11D5-8488-00D059066040}')!

!Decorator categoriesForClass!Drawing! !
!Decorator methodsFor!

draw
^self subclassResponsibility!

initvc: vc
vcobj:=vc!

newDec: vc x: xd y:yd
|temp|
temp:= self new.
x:=xd.
y:=yd.
self initvc: vc.
^temp
!

x: xd y: yd
x:=xd.
y:=yd! !
!Decorator categoriesFor: #draw!*-subclass responsibility!drawing!public! !
!Decorator categoriesFor: #initvc:!accessing!public! !
!Decorator categoriesFor: #newDec:x:y:!instance creation!public! !
!Decorator categoriesFor: #x:y:!accessing!public! !

----------------------------------
"Filed out from Dolphin Smalltalk 2000 release 4.01"!

VisualComponent subclass: #TextView
 instanceVariableNames: 'text'
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
TextView comment: ''!

TextView guid: (GUID fromString: '{6C120F04-F0B4-11D5-8488-00D059066040}')!

!TextView categoriesForClass!Unclassified! !
!TextView methodsFor!

getText
^text!

setText: tx
text:=tx! !
!TextView categoriesFor: #getText!accessing!public! !
!TextView categoriesFor: #setText:!accessing!public! !
-------------------------------------
"Filed out from Dolphin Smalltalk 2000 release 4.01"!

Decorator subclass: #BorderDecorator
 instanceVariableNames: 'size'
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
BorderDecorator comment: ''!

BorderDecorator guid: (GUID fromString:
'{6C120F05-F0B4-11D5-8488-00D059066040}')!

!BorderDecorator categoriesForClass!Unclassified! !
!BorderDecorator methodsFor!

draw
!

getSize
^size!

newBorder: vc siz: sz
^self new;
setSize: sz.
super initvc: vc!

setSize: sz
size:=sz!

updateBorder: sz
self initSize: sz.
self draw! !
!BorderDecorator categoriesFor: #draw!drawing!public! !
!BorderDecorator categoriesFor: #getSize!accessing!public! !
!BorderDecorator categoriesFor: #newBorder:siz:!instance creation!public! !
!BorderDecorator categoriesFor: #setSize:!accessing!public! !
!BorderDecorator categoriesFor: #updateBorder:!drawing!public! !

-------------------------
"Filed out from Dolphin Smalltalk 2000 release 4.01"!

Decorator subclass: #ScrollDecorator
 instanceVariableNames: 'xpos ypos'
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
ScrollDecorator comment: ''!

ScrollDecorator guid: (GUID fromString:
'{6C120F03-F0B4-11D5-8488-00D059066040}')!

!ScrollDecorator categoriesForClass!Unclassified! !
!ScrollDecorator methodsFor!

draw!

newScroll: vc x: xd y: yd xps: xp yps: yp
^self new.
super x: xd y: yd.
xpos:=xp.
ypos:=yp.
super initvc: vc!

scrollTo! !
!ScrollDecorator categoriesFor: #draw!*-unclassified!public! !
!ScrollDecorator categoriesFor: #newScroll:x:y:xps:yps:!instance
creation!public! !
!ScrollDecorator categoriesFor: #scrollTo!*-unclassified!public! !

-------------


Reply | Threaded
Open this post in threaded view
|

Re: Please...help...

Ken Lee
> I'm also implementing decorator in smalltalk. I would like to do a
ScollBar
> and a Border decorator for a textView...like in "DESIGN PATTERNS -
ELEMENTS
> OF REUSABLE OBJECT-ORIENTED SOFTWARE" book by "E. GAMMA, R. Helm...".

You might find it helpful to obtain a copy of "The Design Patterns Smalltalk
Companion", which covers the same material, using Smalltalk examples. It is
by Alpert, Brown, and Woolf. The publisher is Addison-Wesley. In my
experience, it does a better job, discussing the same basic material, and
goes on to give even better illustrations.

Best wishes,

Ken Lee