Submodules passed in the Ctor and Derived Properties

Recently a programming buddy and I were discussing various options for the population of various properties to a UI-oriented class from a generated Database - oriented class that "kind of" belongs with it. The idea was, he is generating the DB classes from stored procedures using a code - generator and it isn't feasible to change them around. However, he needed the flexibility to bring some or all of the properties in an instance of one of these DB - oriented classes into his UI-oriented class, allowing for the most flexibility without having to hard - code stuff or use reflection.

I suggested a possibility that I've used before: Pass an instance of the DB class into the Ctor of the UI class and store it in a private field there. Then, you can rig up the UI-class properties, fields or members in any way you want. This is far from a new idea - but our little exercise made me think how few times I've seen developers use this technique. Here's a simplistic illustration:

class MyUIClass
{

private MyDBClass _subModule;
public MyUIClass(MyDBClass subModule)
{
this._subModule=subModule;
}

private string _myUIProperty;
public string MyUIProperty
{
get
{
return _myUIProperty;
}

set
{
_myUIProperty =this._subModule.WhateverPropertyOrExpression;
}
}
// ....
}

Comments

Popular posts from this blog

FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX

Some observations on Script Callbacks, "AJAX", "ATLAS" "AHAB" and where it's all going.

IE7 - Vista: "Internet Explorer has stopped Working"