标签:需要 oda cpp eth 外观模式 class 实现 关联关系 外观
外观模式,我的理解就是模块封装。比如要实现A类,需要B\C\D三个类,客户调用A类成员函数,A类调用B\C\D。对应客户看不到bcd,只能看到A,因此成为外观模式。这里理解为关联关系。
//复杂或多对象 class objectOne { public void operator() { cout<<"operator one\n"; } } class objectTwo { public void operator() { cout<<"operator two\n"; } } class objectThree { public void operator() { cout<<"operator three\n"; } } class objectFour { public void operator() { cout<<"operator four\n"; } } //外观实现 class Facade { objectOne one; objectTwo two; objectThree three; objectFour four; public Facade() { obj1 = new objectOne(); obj2 = new objectTwo(); obj3 = new objectThree(); obj4 = new objectFour(); } public void MethodA() { cout<<" Fun A()-----\n"); obj1.operator(); obj2.operator(); obj3.operator(); obj4.operator(); } public void MethodB() { cout<<" Fun B()-----\n"); obj4.operator(); obj3.operator(); obj2.operator(); obj1.operator(); } } //调用 void main() { Facade facade = new Facade(); facade.MethodA(); facade.MethodB(); }
标签:需要 oda cpp eth 外观模式 class 实现 关联关系 外观
原文地址:https://www.cnblogs.com/jylz/p/10648338.html