设计模式:组合与迭代器模式解析
1. 组合模式
1.1 绘图方法实现
在绘图相关操作中,不同对象的绘图实现方式有所不同。例如,Vertex 的 drawWithContext: 方法实现如下:
- (void) drawWithContext:(CGContextRef)context
{
CGFloat x = self.location.x;
CGFloat y = self.location.y;
CGContextAddLineToPoint(context, x, y);
}
而 Stroke 对象的 drawWithContext: 方法则需要先将上下文移动到其子元素的第一个点,然后使用 Quartz 2D 函数完成整个线条绘制操作:
- (void) drawWithContext:(CGContextRef)context
{
CGContextMoveToPoint(context, self.location.x, self.location.y);
for (id <Mark> mark in children_)
{
[mark drawWithContext:context];
}
CGContextSetStrokeColorWithColor(context,[self.color CGColor]);
CGContextStro
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



