G
Guest
Hi
Has anyone encountered the following situation (I cant believe I am the
first.)
As part of a system I am designing I require a collection class that
populates itself.
So far I have a design along the following lines.
public interface IFactory
{
IItem NewItem();
IItem[] NewItem(int count);
}
public interface IItem
{
void Load(OLEDBCommand Command); Implementers load internal values by
executing command
void Load(OLEDBDataReader DataReader);Implementers load internal values by
reading current record.
}
public interface ISelfLoadingCollection
{
void Load(OLEDBCommand command , IFactory factory, bool loadAll);
}
public class SomeItemClass :IItem
{
.... Implementation of IItem and other class specific stuff. (You get the
general idea)
}
public class SomeItemClassFactory:IFactory
{
....Implementation of the IFactory stuff.
IItem NewItem()
{
return new SomeItem();
}
}
public class SelfPopulatingCollection : DictionaryBase, ISelfLoadingCollection
{
.... Implements self loading collection stuff and exposes strongly typed
dictionary of IItem's
void Load(OLEDBCommand command , IFactory factory, bool loadAll);
{
Code here calls ExecuteReader on command, loops through rows
calls newitem on the factory and passes the DataReader to the new IItem.
The new IItem is then added to the dictionary.
}
}
In the app I intend to create a new instance of the
SelfPopulatingCollection, call the Load passing in the correct factory and
command and watch it do its work.
Why ? well I only want to write my collection management code the once and
have all collections load the same way across my system (there are other
reasons.)
I am sort of happy with the design but it doesn’t feel entirely natural. The
factory part seems inelegant (maybe the whole design is.) So I thought maybe
someone had a better pattern for this. Who knows? rip it/me to shreds then
ladies and gents.
Regards
Ben.
Has anyone encountered the following situation (I cant believe I am the
first.)
As part of a system I am designing I require a collection class that
populates itself.
So far I have a design along the following lines.
public interface IFactory
{
IItem NewItem();
IItem[] NewItem(int count);
}
public interface IItem
{
void Load(OLEDBCommand Command); Implementers load internal values by
executing command
void Load(OLEDBDataReader DataReader);Implementers load internal values by
reading current record.
}
public interface ISelfLoadingCollection
{
void Load(OLEDBCommand command , IFactory factory, bool loadAll);
}
public class SomeItemClass :IItem
{
.... Implementation of IItem and other class specific stuff. (You get the
general idea)
}
public class SomeItemClassFactory:IFactory
{
....Implementation of the IFactory stuff.
IItem NewItem()
{
return new SomeItem();
}
}
public class SelfPopulatingCollection : DictionaryBase, ISelfLoadingCollection
{
.... Implements self loading collection stuff and exposes strongly typed
dictionary of IItem's
void Load(OLEDBCommand command , IFactory factory, bool loadAll);
{
Code here calls ExecuteReader on command, loops through rows
calls newitem on the factory and passes the DataReader to the new IItem.
The new IItem is then added to the dictionary.
}
}
In the app I intend to create a new instance of the
SelfPopulatingCollection, call the Load passing in the correct factory and
command and watch it do its work.
Why ? well I only want to write my collection management code the once and
have all collections load the same way across my system (there are other
reasons.)
I am sort of happy with the design but it doesn’t feel entirely natural. The
factory part seems inelegant (maybe the whole design is.) So I thought maybe
someone had a better pattern for this. Who knows? rip it/me to shreds then
ladies and gents.
Regards
Ben.