By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Good idea or bad idea?

P: n/a
Hi,
My application creates a project that is structured like a tree, so i
want to use a treeview to display it to the user.

Would it be a good idea to create the various parts of project as
classes inherited from TreeNode and then just add them to the treeview
(ie adding extra properties to the inherited classes to hold my data)?
This would make outputting the project as an xml file very simple as i
could just traverse the treeview and get the nodes to write their part
of the document.

Or is it a better idea to create separate classes to hold my data, and
place them in the .Tag of a normal treenode?

Or is their another way i should do this?

Basically, is mixing the 'data' with the UI a good idea? I thought i
read somewhere that it is a bad idea :(.

Cheers,
James.

Jan 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The fact that you're asking this question shows that your subconscious is
trying to tell you that mixing UI and data classes is almost always a bad
idea. Generally one makes the data classes (business object classes)
independent of any particular type of user interface, because it gives one
the most flexibility in creating interfaces to the business objects - some
of which might not even be interactive user interfaces.

So plunking the object into the Tag property of a TreeNode isn't a bad idea,
or if you have a collection of those business objects at hand you might just
store in the Tag a value that you could use as a lookup into the collection
(an ID or other unique key). But "storing the object" in the Tag isn't
expensive anyway, since you're actually just storing a reference to the
object, which is probably just a four- or eight-byte value depending on
whether you're on a 32-bit or 64-bit operating system.

Tom Dacon
Dacon Software Consulting

"pigeonrandle" <pi**********@hotmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hi,
My application creates a project that is structured like a tree, so i
want to use a treeview to display it to the user.

Would it be a good idea to create the various parts of project as
classes inherited from TreeNode and then just add them to the treeview
(ie adding extra properties to the inherited classes to hold my data)?
This would make outputting the project as an xml file very simple as i
could just traverse the treeview and get the nodes to write their part
of the document.

Or is it a better idea to create separate classes to hold my data, and
place them in the .Tag of a normal treenode?

Or is their another way i should do this?

Basically, is mixing the 'data' with the UI a good idea? I thought i
read somewhere that it is a bad idea :(.

Cheers,
James.

Jan 22 '07 #2

P: n/a
Tom,
Cheers for your thoughts. I have already started rewriting what i had
'done' and was looking for somebody to slap me on the back and say
'shrewd move' :o).

Thanks again,
James.
Tom Dacon wrote:
The fact that you're asking this question shows that your subconscious is
trying to tell you that mixing UI and data classes is almost always a bad
idea. Generally one makes the data classes (business object classes)
independent of any particular type of user interface, because it gives one
the most flexibility in creating interfaces to the business objects - some
of which might not even be interactive user interfaces.

So plunking the object into the Tag property of a TreeNode isn't a bad idea,
or if you have a collection of those business objects at hand you might just
store in the Tag a value that you could use as a lookup into the collection
(an ID or other unique key). But "storing the object" in the Tag isn't
expensive anyway, since you're actually just storing a reference to the
object, which is probably just a four- or eight-byte value depending on
whether you're on a 32-bit or 64-bit operating system.

Tom Dacon
Dacon Software Consulting

"pigeonrandle" <pi**********@hotmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hi,
My application creates a project that is structured like a tree, so i
want to use a treeview to display it to the user.

Would it be a good idea to create the various parts of project as
classes inherited from TreeNode and then just add them to the treeview
(ie adding extra properties to the inherited classes to hold my data)?
This would make outputting the project as an xml file very simple as i
could just traverse the treeview and get the nodes to write their part
of the document.

Or is it a better idea to create separate classes to hold my data, and
place them in the .Tag of a normal treenode?

Or is their another way i should do this?

Basically, is mixing the 'data' with the UI a good idea? I thought i
read somewhere that it is a bad idea :(.

Cheers,
James.
Jan 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.