Dear experts,
I am developing a 3 tier application (in VB.NET 9 with framework 3.5 but this doesn't matter much) which uses a given XML file as DB. Because of this XML file I want to create an application which retrieves all the data at start up and creates + populates all objects accordingly. My philosophy for this app is to retrieve every instance of an object once. And this credo is actually what gave me problems to solve this the cleanest way possible (which I always strive for).
For this to work let's say I made a module named "MainModule" with a public property named "Categories" typed as "CategoryCollection". CategoryCollection is a class which inherits from BindingList(Of Category). Category is eventually the class with the data of a category. Simple so far right?
The same module also has a property named Stores which is typed as "StoreCollection". StoreCollection also inherits from BindingList(Of Store). Store is the class with the data from one store obviously. But the Store class has a property named "MyCategory" which is typed as Category.
To make sure I don't need to retrieve the category again from the XML file for this store and create another instance for the same category (remember the holy credo I set for myself), I simply find the correct category in the "Categories" property in "MainModule" (this looks like something like store.MyCategory = MainModule.Categories(0)).
--> Let's pretend I found out the correct category is category where index = 0.
This is a very simple example obviously. In my application a category instance can be needed by 3 different other classes or something. Plus the fact that I sometimes need it down the line of 4 objects (or more!). That is why I don't want to pass the category collection along through constructors. It will pass 3 objects who don't need it first so I can facilitate the 4th. That can't be the best practise we can come up with right? This is why I used a module. But I don't like this solution. It's a bit ugly in my opinion. I don't want to approach a module from within a class. I also don't want to make a class with shared properties, because that sounds like the same thing as a module to me (in practise ofcourse). The singleton pattern won't work I think, because i'll have to hold that one single instance in... a what? A module? Same problem...
So you guys see my problem right? I just want to hear what you guys think? What do you guys consider the cleanest way of getting this show on the road?