OOP Noob question

Associate
Joined
3 Oct 2004
Posts
68
Location
Biggin Hill
Hello,

I am a procedural programmer and have started to look at oop programming and have a query I am struggling to get my head around.

Currently, if I am pulling member data from a database I would hold the data in a linked list and can then use this to loop through the members and manipulate as many times as I want. How would I do this using a Member Object, i.e. how do I declare the member object for each member. A lot of examples seem to hardcode the object, i.e. m1, m2 ......

Sorry if not worded correctly or I have not made myself clear, if this is the case please ask for further examples and I will be happy to provide.

Apologies if being incredibly thick :confused:

Many Thanks
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,325
Location
Derbyshire
https://compilr.com/akiller/ocukdean-e-boyoop/

[Expand OCUK.dean_e_boy.OOP on the left, double-click main.cs, hit run to demo it]

Something like that. Pretty much the same as you're doing already by the sounds of it by using a list.

Obviously in a real app you'd separate the various bits (member/memberlogic) into separate .cs files to keep it clean.

edit: beat :o.
 
Associate
Joined
12 Nov 2012
Posts
1,075
Location
Gloucestershire, UK
Ok I think I get what you are asking, so will try and answer with a little pseudo code.

Code:
list = new list
results = database.runQuery

foreach result in results:
    Member m = new Member(/* member params */)
    list.add(m)

creating a new instance of the Member object within the loop and placing it in the list will result in a list of individual member objects, no need to hard code your instances of the member object.

Your Member objects will need some way to be identified and retrieved, you could also swap out the list and use a Key Value Pair object using a unique value within Member as your key.

edit: so the same as the first reply essentially.
 
Back
Top Bottom