473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

inheritance and wrapping (long)

Hi

I am experiencing something weird. maybe you could help me.

I have two ineditable classes from outsource libraries: DataColumn and
GridColumn

I have built a wrapper class around DataColumn like this:

public class MyDataColumn {
// wrapped column
protected DataColumn column;
// additional settings
public bool MyFlag;

// hidden constructor
protected MyDataColumn(DataColumn source) {
this.column = source;
this.MyFlag = true;
}
// public converter
public static explicit MyDataColumn(DataColumn source) {
MyDataColumn tmp = source.ExtendedProperties["MyDataColumn"] as
MyDataColumn;
if (tmp == null) {
tmp = new MyDataColumn(source);
source.ExtendedProperties["MyDataColumn"] = tmp;
}
return tmp;
}
}

The purpose of this class is to build a wrapper class and calculate the
extension (MyFlag) upon which store the settings in ExtendedProperties of
the source DataColumn so as long the original DataColumn exists, all calls
to the MyDataColumn will return stored results. With that i can do the
following.

DataColumn column;
// create wrapping
{
MyDataColumn wrappedColumn1 = (MyDataColumn) column;
wrappedColumn1.MyFlag = false;
}
// somewhere else on the same dataColumn
MyDataColumn wrappedColumn2 = (MyDataColumn) column;
if (!wrappedColumn1.MyFlag) {
// <- I am here
}

This had worked excelently until today, when I decided to extend the class
with its child to wrap another class, like this:

public class MyGridColumn : MyDataColumn
{
// another wrapped column
private GridColumn gridColumn;
// more additions
public bool MySecondFlag;
// hidden constructor
protected MyGridColumn(MyDataColumn sourceDataColumn, GridColumn
sourceGridColumn)
: base(sourceDataColumn)
{
this.gridColumn = sourceGridColumn;
this.MySecondFlag = true;
}

// public converter
public static explicit MyGridColumn(GridColumn source) {
MyGridColumn tmp = source.Tag as MyDataColumn; // this class use Tag
objects instead of ExtendedProperties objects array
if (tmp == null) {
DataColumn dataColumn = source.GetDataColumn(); // this method return
the dataColumn used by this gridColumn
tmp = new MyGridColumn(dataColumn, source);
source.Tag = tmp;
}
return tmp;
}
}

Okay, this class' object does basicly the same as above, it wraps around the
GridColumn object, stores itself within it.
However I can't access the inherited property, or to put it otherwise I can,
but they return default values like this:

DataColumn column;
MyDataColumn myColumn = (MyDataColumn) column;
myColumn.MyFlag = false;

GridColumn gridColumn = new gridColumn(column);
MyGridColumn myGridColumn = (MyGridColumn) gridColumn;
myGridColumn.MySecondFlag = false;

the result is that
myColumn.MyFlag = false; // ok
myGridColumn.MyFlag = true; // not ok
myGridColumn.MySecondFlag = false; // ok

if I check via debuger, I can see that values are like above,
if (using debuger) I dig deeper like:
myGridColumn.base.column.Table.Columns[column].ExtendedProperty["MyDataColumn"].MyFlag
I see 'false' which is correct value

if I do the double wrapping instead of inheritance like this:
MyGridColumn {
private MyDataColumn myDataColumn;
private GridColumn gridColumn;

// instead of calling base constructor I do: this.myDataColumn =
(MyDataColumn) gridColumn.GetDataColumn();
}

everything works as expected ie none of the above quirks. but force me to
use longer calls: myGridColumn.myDataColumn.MyFlag instead of
myGridColumn.MyFlag

Can anyone explain this? How to make it work. I have this certain under skin
feeling that I miss something obvious here.

CUIN Kaczy
Nov 17 '05 #1
2 1575
I think your title says it all. Can you not inherit these classes?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Andrzej Kaczmarczyk" <ak**********@visualsystems.com.pl> wrote in message
news:ef*************@TK2MSFTNGP15.phx.gbl...
Hi

I am experiencing something weird. maybe you could help me.

I have two ineditable classes from outsource libraries: DataColumn and
GridColumn

I have built a wrapper class around DataColumn like this:

public class MyDataColumn {
// wrapped column
protected DataColumn column;
// additional settings
public bool MyFlag;

// hidden constructor
protected MyDataColumn(DataColumn source) {
this.column = source;
this.MyFlag = true;
}
// public converter
public static explicit MyDataColumn(DataColumn source) {
MyDataColumn tmp = source.ExtendedProperties["MyDataColumn"] as
MyDataColumn;
if (tmp == null) {
tmp = new MyDataColumn(source);
source.ExtendedProperties["MyDataColumn"] = tmp;
}
return tmp;
}
}

The purpose of this class is to build a wrapper class and calculate the
extension (MyFlag) upon which store the settings in ExtendedProperties of
the source DataColumn so as long the original DataColumn exists, all calls
to the MyDataColumn will return stored results. With that i can do the
following.

DataColumn column;
// create wrapping
{
MyDataColumn wrappedColumn1 = (MyDataColumn) column;
wrappedColumn1.MyFlag = false;
}
// somewhere else on the same dataColumn
MyDataColumn wrappedColumn2 = (MyDataColumn) column;
if (!wrappedColumn1.MyFlag) {
// <- I am here
}

This had worked excelently until today, when I decided to extend the class
with its child to wrap another class, like this:

public class MyGridColumn : MyDataColumn
{
// another wrapped column
private GridColumn gridColumn;
// more additions
public bool MySecondFlag;
// hidden constructor
protected MyGridColumn(MyDataColumn sourceDataColumn, GridColumn
sourceGridColumn)
: base(sourceDataColumn)
{
this.gridColumn = sourceGridColumn;
this.MySecondFlag = true;
}

// public converter
public static explicit MyGridColumn(GridColumn source) {
MyGridColumn tmp = source.Tag as MyDataColumn; // this class use Tag
objects instead of ExtendedProperties objects array
if (tmp == null) {
DataColumn dataColumn = source.GetDataColumn(); // this method return
the dataColumn used by this gridColumn
tmp = new MyGridColumn(dataColumn, source);
source.Tag = tmp;
}
return tmp;
}
}

Okay, this class' object does basicly the same as above, it wraps around
the GridColumn object, stores itself within it.
However I can't access the inherited property, or to put it otherwise I
can, but they return default values like this:

DataColumn column;
MyDataColumn myColumn = (MyDataColumn) column;
myColumn.MyFlag = false;

GridColumn gridColumn = new gridColumn(column);
MyGridColumn myGridColumn = (MyGridColumn) gridColumn;
myGridColumn.MySecondFlag = false;

the result is that
myColumn.MyFlag = false; // ok
myGridColumn.MyFlag = true; // not ok
myGridColumn.MySecondFlag = false; // ok

if I check via debuger, I can see that values are like above,
if (using debuger) I dig deeper like:

myGridColumn.base.column.Table.Columns[column].ExtendedProperty["MyDataColumn"].MyFlag
I see 'false' which is correct value

if I do the double wrapping instead of inheritance like this:
MyGridColumn {
private MyDataColumn myDataColumn;
private GridColumn gridColumn;

// instead of calling base constructor I do: this.myDataColumn =
(MyDataColumn) gridColumn.GetDataColumn();
}

everything works as expected ie none of the above quirks. but force me to
use longer calls: myGridColumn.myDataColumn.MyFlag instead of
myGridColumn.MyFlag

Can anyone explain this? How to make it work. I have this certain under
skin feeling that I miss something obvious here.

CUIN Kaczy

Nov 17 '05 #2
>I think your title says it all. Can you not inherit these classes?
quick aneswer, no

longer aneswer in thread
http://www.dotnetnewsgroups.com/news...NewsgroupID=18

but short summary:
I need to be able to persist the extended object data. Because I use typed
datasets, I have no influence on it's creation, which means that, I have to
accept that my typed DataSet consist of specialised DataTables which consist
of specialised DataColumns.

Now If I do something like this:
MyDataColumn : DataColumn
{
public bool MyFlag;

public MyDataColumn() : base ()
{
this.MyFlag = false;
}
}

I couldn't do
DataTable table;
MyDataColumn column = table.Columns["col1"]; // on the right side I have
DataColumns assigned by generator
I couldn't also:

foreach (MyDataColumn column in table.Columns) {
}

I can't write converter because you can't write converters for related
classes (which is plain stupid constraint btw)

I could do
MyDataColumn column = new MyDataColumn(table.Columns["col1"])

but,
1. this is quite ackward to use
2. the changes wouldn't be persisted

MyDataColumn column1 = new MyDataColumn(table.Columns["col1"])
column1.MyFlag = true;
// later in code (like in another loop through table columns or in temporary
instance when calling subroutines)

MyDataColumn column2 = new MyDataColumn(table.Columns["col1"])
if (column2.MyFlag) {
// I should be here, but I wouldn't with inheritance
}

colum1 and column2 points at two different and unrelated objects. I could of
course store all the data in the ExtendedProperties but this mechanis isn't
universal, isn't typesafe, and use string search which is slow

because both of those objects are using some existing object as a data
source, it is a schoolbook case for wrapping not for inheritance

I'd love to use inheritance here, but can not and was convinced in the
thread I pointed above.

as for this case, I'd like to use inheritance (I've included my attempt in
my previous mail), but the results are weird (the inherited properties
aren't set), and I don't understand why. Again using wrapping helped, but
the syntax is unwieldy.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
A watched clock never boils.

[snip unnecessary paste]

CUIN Kaczy
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
20
by: Steve Jorgensen | last post by:
A while back, I started boning up on Software Engineering best practices and learning about Agile programming. In the process, I've become much more committed to removing duplication in code at a...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Adam Clauss | last post by:
OK, I have class A defined as follows: class A { A(Queue<B> queue) { ... } } Now, I then have a subclass of both classes A and B. The subclass of A (SubA), more specifically is passed a...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
6
by: Markus Ernst | last post by:
Hi Searching for a possibility to display some text with preserved white space and line breaks, but with long lines being wrapped, I found this CSS declaration, which I found helpful: pre {...
6
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance"...
11
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern...
1
by: thedbflow | last post by:
Folks, I have a bit of a quandary I was hoping for some expert guidance on. Keep in mind I am not a C++ developer, but I have worked with the language a bit. I have a native C++ API which I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.