smalltalk: Abstract out the common iteration protocol into a superclass.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 29 Nov 2009 23:26:41 +0000 (23:26 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 Nov 2009 23:26:41 +0000 (23:26 +0000)
smalltalk-fringe.st

index 0d319da..653c31a 100644 (file)
@@ -5,7 +5,19 @@ Smalltalk implementation of a `same-fringe' solver.
 Use GNU Smalltalk syntax -- it seems more Emacs-friendly.
 "
 
-Object subclass: Node [
+Object subclass: BasicNode [
+    <comment: 'I am provide common behaviour for my subclasses Node and
+LeafNode.  Otherwise, I''m not particularly interesting.'>
+
+    iterator [
+       "Return a new iterator to walk this node."
+
+       <category: 'iteration'>
+       ^NodeIterator for: self
+    ]
+]
+
+BasicNode subclass: Node [
     | left right data |
 
     <comment: 'I represent simple binary tree nodes.  My instances consist of
@@ -69,13 +81,6 @@ instances of LeafNode.'>
        ^false
     ]
 
-    iterator [
-       "Answer a new iterator to walk this node."
-
-       <category: 'iteration'>
-       ^NodeIterator for: self
-    ]
-
     inorderTell: aBlock tell: aNodeIterator [
        "This is the hairy part of the iteration protocol.
 
@@ -179,7 +184,7 @@ PositionableStream extend [
     ]
 ]
 
-Object subclass: LeafNode [
+BasicNode subclass: LeafNode [
     <comment: 'I represent the leaves of a tree of Nodes.  I don''t hold any
 kind of interesting state.  My methods provide the base cases for some of the
 recursive protocols used to handle Nodes.'>
@@ -201,13 +206,6 @@ recursive protocols used to handle Nodes.'>
        ^true
     ]
 
-    iterator [
-       "Return a new iterator to walk this node."
-
-       <category: 'iteration'>
-       ^NodeIterator for: self
-    ]
-
     inorderTell: aBlock tell: aNodeIterator [
        "This is the hairy part of the iteration protocol.