Designing a drawing class hierarchy in iOS
<p>My end goal is to draw a report that looks like MS Word using Quartz into a UIView, having and then having that UIView in a UIScrollView.</p>

<p>What I have now is a top level Report Object, and then it's children are parts of the report to draw like ReportTitle, ReportTable, ReportSplitColumn, etc.  The top level Report Object looks like:</p>

<pre><code>@property (nonatomic, retain) UIFont *font;
@property (nonatomic, assign) CGFloat margins; 
@property (nonatomic, assign) TextObjectStyle style;
@property (nonatomic, assign) CGColorRef color;

- (CGSize)size;
</code></pre>

<p>In my proof of concept, I created a ReportView object that knows how to draw ReportObjects that take a specific ReportObject, and draws it at a specific point.  So my drawRect would like something like:</p>

<pre><code>//pseudocode
drawRect: {
  //get the current context
  CGFloat startHeight = 0;
  CGPoint point = CGPointMake(0, startHeight);
  startHeight += [self drawReportTitle:currentContext atPoint:CGPointMake(0, point.y)].height;
  point.y = startHeight;

  startHeight += [self drawParagraph:currentContext withText:paragraphs atPoint:CGPointMake(0, point.y)].height;
  point.y = startHeight;

}
</code></pre>

<p>What I started trying to do was have my ReportView have a property of <code>NSArray *ReportObjectsArray</code> and then have my caller class set that value, and then have my ReportView draw it.  I was hoping I could do something like:</p>

<pre><code>for (ReportView *r in self.ReportObjectsArray) {
  startHeight += [self drawReportObject].height atPoint:CGPointMake(0, point.y;
  point.y = startHeight
}
</code></pre>

<p>Except the problem I realize is, my own classes don't know how to draw themselves.  I think I remember seeing this pattern in a Java book where the class knows how to draw itself.  And that does make sense to me.  However the problem I ran into was in the end, I want one UIView of type ReportView that is scrollable in UIScrollView.  I wasn't really sure if each ReportObject should subclass UIView instead and then add each of these objects to the UIView in the scrollView as a subView, and then have it draw itself that way.  Is that the better way to go?  I'm not really sure.  If it's not, what is my alternative?  Would I have all my classes have a draw method, but in it, it just posts a notification and then in my ReportView class, I can have it listen to those notifications, and then call the appropriate draw methods?  Thanks.</p>
