I’m a kind of new to programming and i wish a simple advice how to proceed. I’ll simply explain my situation.
I have a webpage (Default.aspx), 2 classes (Class1, Class2) and 15 ArrayLists.
Step 1) In Default.aspx when a user click a button i create a new instance of Class1:
Class1 objClass1 = new Class1();
Step 2) In Class1, i have 15 ArrayLists where i add data to them. I don’t know the number of elements and i use ArrayList object, not simple arrays. I fill all 15 ArrayLists with data in Class1. All the ArrayLists contain between 10-150 items in them.
Step 3) In Class2 i need all 15 ArrayLists to do some business rules on them in routine Class2BusinessRules. So, i code:
Class2 objClass2 = new Class1();
objClass2.Class2BusinessRules(ArrayList1, ArrayList2, etc..)
So, i pass 15 arraylists as parameters to Class2. What is a better solution to this situation? Class1 and Class2 should exist separately, because they are abstract objects, they serve different purposes. I don’t want to merge them into 1 class. I don’t want to make these 15 ArrayLists static or any kind of global variables, because concurrent users on the website will use them.
Possible solutions:
1) Put all ArrayLists in a separate class
2) Put all ArrayLists into a Dictionay object like Dictionary
What are pros/cons for these 2 solution? Can you share other approriate solutions for my case? Can you tell me any design patter for classes close to my case?
You could pass a reference to Class1 into Class2. That way inside Class2 you cen access the array lists by the Class1 reference.
e.g.