Another design lecture:
not implementation lectureself always represents the receiver
Node >> setWindowWithRatioForDisplay
| defaultNodeSize |
defaultNodeSize := mainCoordinate / maximizeViewRatio.
self window add:
(UINode new
with: bandWidth * 55 / defaultWindowSize).
previousNodeSize := defaultNodeSize.
We want to change the defaultNodeSize formula in a subclass
Duplicate the code in a subclass
Node subclass: OurSpecificNode
...OurSpecificNode >> setWindowWithRatioForDisplay
| defaultNodeSize |
defaultNodeSize :=
(mainCoordinate / maximizeViewRatio) + 10.
self window add:
(UINode new
with: bandWidth * 55 / defaultWindowSize).
previousNodeSize := defaultNodeSize.private attributes makes duplication in subclasses impossibleSubclasses can override such methods
Node >> setWindowWithRatioForDisplay
| defaultNodeSize |
defaultNodeSize := (mainCoordinate / maximizeViewRatio).
self window add:
(UINode new
with: bandWidth * 55 / defaultWindowSize).
previousNodeSize := defaultNodeSize.Node >> setWindowWithRatioForDisplay
| defaultNodeSize |
defaultNodeSize := self ratio.
self window add:
(UINode new
with: bandWidth * 55 / defaultWindowSize).
previousNodeSize := defaultNodeSize.
Node >> ratio
^ mainCoordinate / maximizeViewRatioNode >> ratio
^ mainCoordinate / maximizeViewRatioA subclass can refine the behavior
OurSpecificNode >> ratio
^ super ratio + 10Node >> setWindowWithRatioForDisplay
| defaultNodeSize |
defaultNodeSize := self ratio.
self window add:
(UINode new
with: bandWidth * 55 / defaultWindowSize).
previousNodeSize := defaultNodeSize.
We can also extract the UINode instantiation.
Node >> setWindowWithRatioForDisplay
| defaultNodeSize |
defaultNodeSize := self ratio.
self window add: self uiNode.
previousNodeSize := defaultNodeSize.Node >> uiNode
^ UINode new
with: bandWidth * 55 / defaultWindowSizeNode >> uiNode
^ UINode new
with: bandWidth * 55 / defaultWindowSizeNode >> uiNode
^ self uiNodeClass new
with: bandWidth * 55 / defaultWindowSize.Node >> uiNodeClass
^ UINodeSmall messages are a sign of good design
Node >> uiNode
^ self uiNodeClass new
with: bandWidth * 55 / defaultWindowSize.Node >> uiNode
^ self uiNodeClass new
with: bandWidth * self averageRatio / defaultWindowSize.
Node >> averageRatio
^ 55How to let the class users change the value?
Node >> averageRatio
^ averageRatio ifNil: [ self defaultAverageRatio ]
Node >> defaultAverageRatio
^ 55
Node >> averageRatio: aNumber
averageRatio := aNumber
/