模型数据的变化会引起视图的变化,这个可以用观察者模式实现,而多视图之间的关系可以用
组合模式实现
class CSubject//观察者模式
{
public:
CSubject(tagCArray *solid, tagCArray *select){m_solid = solid, m_select = select;}
virtual ~CSubject(){}
void SetObserver(CMcadView *view){m_view = view;}//设置观察者
void Notify()
{
if (m_view)
{
m_view->UpdateView();
}
}
void DrawSolid(CDC *pDC, int DrawMode);//重画实体和选择集,双存
private:
CMcadView *m_view;
tagCArray *m_solid;
tagCArray *m_select;
void CSubject::DrawSolid(CDC *pDC, int DrawMode)
{
for (int i = 0; i < m_solid->GetSize(); i++)
{
(*m_solid)[i]->DrawSolid(pDC, DrawMode);
}
for (int m = 0; m < m_select->GetSize(); m++)
{
(*m_select)[m]->DrawSolid(pDC, Select);
}
}