Saturday, January 7, 2012

Programming Assignment 1: PCS Tree

PA1 has been assigned. I've taken a couple of days to let it simmer on the back burner for a bit, and I've come up with two possible ways to do this.

Approach #1

My first solution is to use the Composite Pattern, which is appropriate for many tree applications.  Here's the breakdown for this solution.

  • PCSTree: The tree as a single unit that encapsulates a pointer to a PCSComponent root node.
    • PCSComponent: An abstract class to be extended into leaf nodes as well as composite nodes.
      • PCSNode: A leaf on the PCS tree. Extends PCSComponent.
      • PCSComposite: A node that encapsulates a PCSList. Extends PCSComponent.
        • PCSList: A linked list of PCSComponent objects.
Here's a partial class diagram of this solution.



Approach #2

My second approach is a less elegant but simpler version of the first.  Since all nodes in this system are technically the exact same data type, it didn't seem to make sense to distinguish between them the way the Composite Pattern does.  Instead, PCSNode can just encapsulate PCSList, and if its list is empty, that simply means it's a leaf.

Here's a class diagram.



I'm going for the second approach.  I'll let you know how it goes.

No comments:

Post a Comment