Board index » delphi » Design puzzle - how to maintain strategies for named list items across lists

Design puzzle - how to maintain strategies for named list items across lists

Here's a weekend puzzle to solve for yas.  :)  What's the best way to handle
this in Delphi?

I have a class that's used to define the indvidual items in a list.  Each of
these list items have distinguishable names (via a Name property), somewhat
like how fields in a dataset record have distinguishable names.  Another
class that encapsulates the list sets "behavior properties" for each named
item depending on what its name is.  Not all of these properties are scalar
types; some are list objects (like a list of possible values).  I'd like to
store these "per-name behavior properties" in one place rather than with
each list item.  I thought of creating a "strategy singleton" that maintains
strategies (set of behavior property settings) for each possible list item
name, and I would have each instantiated list item point to their strategy
in the singleton.  However, I don't want the strategy singleton to know in
advance what strategies it's storing for the list items until the first list
encapsulating class is instantiated.  In fact, I'd want the strategies to be
dynamic so that they could be changed midstream and immediately affect a
named item (for each changed strategy) throughout all the item lists.

Have I lost anybody?  :)

--

Steve Magruder (www.stevemagruder.com)

 

Re:Design puzzle - how to maintain strategies for named list items across lists


Quote
On Fri, 23 Aug 2002 17:20:09 -0400, "Steve Magruder" <st...@stevemagruder.com> wrote:
> I have a class that's used to define the indvidual items in a list.  Each of
> these list items have distinguishable names (via a Name property), somewhat
> like how fields in a dataset record have distinguishable names.  Another
> class that encapsulates the list sets "behavior properties" for each named
> item depending on what its name is.  Not all of these properties are scalar
> types; some are list objects (like a list of possible values).  I'd like to
> store these "per-name behavior properties" in one place rather than with
> each list item.  I thought of creating a "strategy singleton" that maintains
> strategies (set of behavior property settings) for each possible list item
> name, and I would have each instantiated list item point to their strategy
> in the singleton.  However, I don't want the strategy singleton to know in
> advance what strategies it's storing for the list items until the first list
> encapsulating class is instantiated.  In fact, I'd want the strategies to be
> dynamic so that they could be changed midstream and immediately affect a
> named item (for each changed strategy) throughout all the item lists.
> Have I lost anybody?  :)

I won't know until I check the map again... *ruffling in the glove compartment*

Something along the lines of:

  ItemStrategy := ItemStrategies.StrategyByName(ListItem.Name);
  if ItemStrategy<>nil then
  begin
    ItemStrategy.Refresh(ListItem);
    ItemStrategy.SaveToStream(ListItem);
  end;

Where:
  TItemStrategyClass = class of TItemStrategy;
  ItemStrategies is a singleton with a list of corresponding TItemStrategyClasses and item names, so that in your
initialization sections, you would have:

initialization
  ItemStrategies.Add('DateArray',TDateArrayStrategy);

If you wanted to use Demeter's Law, you could go a little further:

  ItemStrategies.Refresh(ListItem);
  ItemStrategies.SaveToStream(ListItem);

And have the ItemStrategies look up the corresponding class itself, but that might expose the ListItem to the singleton
unnecessarily.

Am I on the right track? :)  Not far enough? :)  I won't bring out the interface-based factory patterns artillery unless
cajoled ;)

-- Ritchie Annand
Senior Software
http://www.malibugroup.com
http://members.shaw.ca/nimble

Re:Design puzzle - how to maintain strategies for named list items across lists


Quote
"Ritchie Annand" <ritch...@spamcop.net> wrote in message

news:1103_1030144864@forums.borland.com...
Quote
> Am I on the right track? :)  Not far enough? :)  I won't bring out the

interface-based factory patterns artillery unless

Quote
> cajoled ;)

Possibly on the right track... thank you.  I need to think about this issue
a little more before putting out a more complete reply.

Steve

Other Threads