I am new to programming and trying to work on a simple console app. I am making a simple Library Management system where the user/admin can manage members and item.
Attaching the menu so it's clear to understand what I am saying.
So far I have only looked at Item and Member Management (option 1 and 2)
Few question I had:
1. In terms of the design approach I am taking.
One class to hold Member details, one for Item details - just instance vars and getters/setters
One class called LibraryManagement, which hold most of the main functionality. From here members and items will be added, edited, deleted based on user input.
One class called Menu, which only hold the Main, member and Item menu for code clarity.
====Does this seem like a reasonable design approach? ====
2. So far I have completed the Manage Member functionality. I realise that the Item Management works exactly the same way as Member management. Only diff is that a newly created item object gets added to List<Item> as opposed to member being added to List<Member> .
It seems like a waste to repeat everything and just replace List<Member> with List<Item> and Member with Item object.
I am trying to find out a way so I can use the same method to add, edit and delete details from the List and only use a generic method where the type is detected at runtime.
A snippet of some relevant code:
class LibraryManagement
{
....
Member mem;
List<Member> memberList = new List<Member>();
....
//Right now for example my method is:
public void AddMember(Member member, List<Member> listOfMembers)
{ listOfMembers.Add(member);}
//which gets called after the appropriate object is created:
public void manageMember()
{
.....
mem = new Member(id, name, address, email);
AddValues(mem, memberList);
....
}
...
}
If and how can I convert it into something generic, something like this:
addDetails<T, U>(t memberItem, U list){{ list.Add(memberItem);} //where U is a genric List and T is just any Type(in my case an Object)
and be able to call the method this way:
AddDetails(mem, memberList)
AddDetails(item, itemList)