Hello All,
I've decided that this OOP thing is not just a fad. With
that in mind, I'm desparately trying to get rid of my
function-oriented design paradigm and switch to a more
object-centric view of the world. Migrating some aspects
of my antiquated style has been straight-forward. For example:
I used to do this:
<old style>------------------------
public class Widget()
{
public string property1;
public string property2;
}
.... Somewhere in a "Datahandle r" class:
public Widget fetchWidget(int widgetid)
{
Widget w = new Widget();
.... do some database spelunking...
w.property1=... .
w.property2=... .
return w;
}
</old style>---------------------------
But now I do this
<new style>----------------------------
public class Widget()
{
private string _property1;
{
set
{ ... etc.
private string _property2;
{
set
{ ... etc.
public Widget(){}
public Widget(int widgetid)
{
this.fetchMe(wi dgetid);
}
private void fetchMe(int widgetid)
{
.... do some database spelunking...
.... poulate internal vars. ...
}
}
</new style>--------------------------
But what about collections of Widgets?
Continuing on from the first example above. In the same "Datahander s"
class, I used to have a method like:
<old style>---------------------------------------------------------
public ArrayList callingAllWidge ts()
{
ArrayList widgets = new ArrayList();
.... database spelunking....
foreach (whatever)
{
Widget w = new Widget();
w.property1=... etc.
...
widgets.Add(w);
}
return widgets;
}
</old style> -------------------------------------------------------
Obviously, there's no reason I couldn't use the same design using the
more updated version (the new style) of a widget, i.e:
public ArrayList callingAllWidge ts()
{
ArrayList widgets = new ArrayList();
.... database spelunking....
foreach (whatever)
{
Widget w = new Widget(foreachv alue);
widgets.Add(w);
}
return widgets;
}
but this seems like cheating ;) Is there a better, more universally
accepted superterrific way? Should i use a corresponding collections
class with an Indexer? Should I create some souped up IList
implemenation? I could certainly see the benefit of a class that
specialized in providing some aggregators (i.e. add all the Widgets
property1 values) but this isn't always necessary.
Thanks in advance..