|
-
Sep 21st, 2010, 10:52 AM
#1
Thread Starter
Addicted Member
Object design
Ok, this question is a bit hard to formulate, when not knowing the answers.. So plz bear with me..
I think (?) this is about object design, and perhaps about structural and/or creational patterns. But a bit hard to say when I only know a couple of patterns yet..
Consider these classes:
Code:
Class A
public products as List(Of Product)
Class Product
public nameID as String
public component as Component
Class Component
public nameID as String
public t As T
So; In class A, each element of the products list has their own component instance, which can all change independently and being saved in this nested structure if an instance of A is serialized to file.
But... what if we INSTEAD want each Product instance only to (in some way) refer to one instance of a specific list of Components. So we wan't to save the products list to one file, and the components list to another file. Then would I build the objects the same way, or different? So let's then say we have now Class B as below.
Code:
Class B
public products as List(Of Product)
public components as List(Of Component)
Now, how would the Product class look like in this case? Exactly the same as above? My intuition says it would now be smarter to just refer to the Component with an ID property:
Code:
Class Product
public nameID as String
public componentID as String
Why?
1. Will not need to update each component variable of the products list when the components list changes.
2. If the Product object shall be shown in a DataGridView, for editing properties, it seems easier to implement the selection of the component property.
Is this wrong approach? Is it suitable in some cases, and if so, when? Are there other solutions I perhaps am not aware of that would be appropriate?
Is this about structural design patterns? and if so, can the alternatives above be catagorized to some pattern type?
I don't really know exactly what I'm looking for.. But I think probably I'm looking to understand whether the object design will be determined by the way the objects are saved.. And if i shall save the objects by serializing to file, vs saving to a database, would I create the business objects differently?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|