Iterator Pattern Code Review
Define the Node and Person Objects
Code Review
- Iterator Pattern Code Review: Define the Main Tree Object
- Iterator Pattern Code Review: Define the Node and Person Objects
- Iterator Pattern Code Review: Use the Iterator Pattern
Code Walkthrough
The Node class (object) represents the definition of a node in the tree structure.
class Node
{
public Node Child { get; set; }
public Node Next { get; set; }
public Person Data { get; set; }
public Node(Person data, Node child, Node next) { this.Data = data; this.Child = child; this.Next = next; } }
public Node(Person data, Node child, Node next) { this.Data = data; this.Child = child; this.Next = next; } }
The Child property represents the first child node of the current node. The Next property represents the node to the right of the current node. The Data property represents the data stored for a particular node.
The Person class (object) represents the custom properties required for a person stored in the tree structure.
class Person
{
public String Name { get; set; }
public Int32 Birth { get; set; }
public Person(String name, Int32 birth) { this.Name = name; this.Birth = birth; }
public override string ToString() { return (String.Format("[{0}, {1}]", this.Name, this.Birth)); } }
public Person(String name, Int32 birth) { this.Name = name; this.Birth = birth; }
public override string ToString() { return (String.Format("[{0}, {1}]", this.Name, this.Birth)); } }
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!