3

I'm creating an object hierarchy that is representing a table that is draw on a control. My hierarchy looks like this :

Table has multiple pages
Page has multiple lines
Line has multiple cells
Cell has multiple glyph

I want to have an option (a parameter) on the table to filter the column (cells) displayed. The client code can do something like this:

myTable.ShowColumns(8,12) // Will display columns 8 to 12

Displaying and placing cells on the control is the responsibility of the Lines objects.How can I pass the informations of which cells are to be displayed from the Table object to the Line object?

Should I give each line a reference to the table object? Should I try to pass the informations to each lines through the hierarchy each time Table.ShowColumns() is called?

There must be an elegant way?

4

2 に答える 2

2

デザインパターンは必要ないと思います。(または、私はそれをそのように呼びません) 子が親にリンクし、その逆の場合に二重リンクを使用しないのはなぜですか?

于 2009-12-01T14:52:24.973 に答える
1

私の理解が正しければ、あなたが祖先と呼んでいるものは、実際には階層内の親であり、実際にはツリーに過ぎない場合です。また、ツリーでは、子ノードがそれぞれの親を参照するようにするのが一般的です。

ShowColumns 関数の設計に関しては、Lines クラスの同様の内部関数呼び出しによって、(セルを保持する) Lines クラスの内部状態変数を変更する必要があると思います。

// something like this..
Table.ShowCollumns -> Table.m_lines.SetVisibleColumns -> (modify visible columns)

明らかに、列からページへの論理マッピング、およびページからテーブルへの論理マッピングによっては、LinesクラスでSetVisibleColumnsを呼び出す前に、さらに別の呼び出しを割り込まなければならない場合があります。Table.FindPageWithColumns(...)

于 2009-12-01T14:54:40.913 に答える