Matching Algorithm Framework: Continued

Q1. T_method可能有一些可设置的状态和属性,如是否输出详细信息、是否做一些特殊的处理等等。对于一个像matcher这样的设计,在何处调整呢?

A1. 一种实现是先产生一个method对象,设置完属性后将该对象作为参数传递给matcher的构造函数:
T_method myMethod;
myMethod.setSomething_1().setSomething_2();
matcher myMatcher(myMethod);

这种方法看起来不太漂亮…

还有一种是由matcher继承method,自然就可以在matcher中设置属性了:
class matcher : public T_method;
matcher myMatcher;
myMatcher.setSomething_1().setSomething_2();

缺点是这样暴露了T_method的实现(而且我现在还不知道这么写能不能通过编译);虽然可以通过改成private继承克服这一点,可这样又不可能访问到setSomething_1(),setSomething_2()等方法…也许可以仍然public继承,但是要将T_method的实现和界面分离开。

第三种方法是在matcher中建立一个property域,如:
class T_method{
class property{
static T_method& setSomething();
};
};
class matcher{
typedef T_method::property property;
};
matcher myMatcher;
myMatcher::property.setSomething();

就是还不知道这样做行不行,明天来试。

发表评论?

3 条评论。

  1. 冰冰,进展如何呀?

  2. 没空弄
    哇哇哇呀呀

  3. 。。。你又开始叫X了

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

Switch to our mobile site