Ah, yes, of course they are. Completely forgot it just stores pointers to the objects. Thanks for pointing that out!! As I said, it's been a while! Thanks for your help :-)
DaveHopeDev1
Posts
-
Need some tips... Sharing a collection of classes for display in a listbox? -
Need some tips... Sharing a collection of classes for display in a listbox?Thanks Luc. Yes, I could just iterate through the dictionary and populate the listbox but my concern is that I would be exposing the 'master' collection to the form. From an abstraction point of view I was trying to avoid this and only allowing a method (parkinglot.displayitems) to output the contents of the dictionary in a read only form (currently a string that is formatted ready to just display in the textbox)... this is where I've now got confused! Do I just return a copy of the dictionary from this method or some other collection (which I can then iterate through or bind to), or do I just expose the master dictionary object? I'm trying to follow/show good design practices with this project :-/
-
Need some tips... Sharing a collection of classes for display in a listbox?Ok, very basic to you guys but I'm hoping someone can offer some advice. I'm making a parking lot windows forms project and have a class structure of: Vehicle Car:Vehicle Van:Vehicle etc. Then a ParkingLot class which declares a private Dictionary collection of type to store all the instances. The key is a parking space code e.g. A1, A2, B1, B2 etc, which then returns the vehicle object associated with that slot in the parking lot. I've made the dictionary private so that all of the functionality is contained in the parkinglot class and the form button presses etc only update the dictionary via public methods in that class for abstraction/separation of concerns (if that's the correct terminology!). The contents of the dictionary are currently displayed in a textbox by calling a parkinglot.displayinventory method which loops through the dictionary items and uses a stringbuilder to create and return the details of all the items to display in the textbox. All was fine, however, now I want to change it to display the contents in a listbox rather than a text box and now I'm questioning whether using a dictionary object was a good idea (I was thinking of the efficiency of retrieval O(1) of dictionary vs O(n) of list and all that). Should I just use a public List which I can then bind to the listbox? But then I thought from an abstraction point of view, having the list of items accessible from the form/view was a bad thing?? Should I stick with a private dictionary for efficient retrieval and create and return a readonlycollection object from the displayinventory method for binding (or something similar)? It's been a while since I've worked with collections and classes and things like this and I've confused myself no end with something so simple! Any tips much appreciated :-)