Modeling Related Objects

I am developing an application that deals with two datasets - Users and Regions. Data is read from files created by a third party. I have a User class and an Area class, and the data is read into the Users array and Areas array (or other appropriate memory structure, depending on the technology we are working with).

Both classes have a unique identifier that is read from the file, and the User class contains an array of area identifiers, providing a link in which one user is associated with many areas.

The requirements are quite simple:

  • a list of users
  • List of areas
  • List of users for the specified area
  • List of areas for specified users

My first thought was to leave the data in two arrays, and then for each of the requirements, have a separate method that will query one or both arrays as needed. That would be easy to implement, but I'm not sure if this is the best way.

Then I thought that the Get Regions method in the User class and Get Users in the Area class would be more useful if, for example, I am at the stage when I have an Area object, I could find it by users by property, but then, as it were, the Get Users method in the Area class knew / had access to the Users array.

, . , , . - - , URL- , ?

UPDATE: , , . .

, " ". , , .

, , , , . , , , , , . , , , , .

+3
7

" ",

User <<--->> Area

3 , , :

User: Id, name, etc.
Area: Id, name, etc.
UserArea: UserId, AreaId
+7

, :

struct/class Membership
{
   int MemberID;
   int userID;
   int areaID;
}

" ". , .

EDIT:

.

:

public bool addMember(Member m)
{
   if (/*eligibility Requirements*/)
   {
      memberList.add(m);
      m.addArea(this);
      return true;
   }
   return false;
}

Member ( )

, , ( )

, , .

, LINQ.

+3

? , " ". , . , , . , OO, /.

+2

, - . . , (--). 101. , .

, . , - . , .

+1

DataTables , .NET ? , Generics, .NET .

0

- 2 . a Dictionary<Area, List<User>> a Dictionary<User, List<Area>>. , . 2 . , .

0

Agree with dacracot

Also look at DevExpress XPO

0
source

Source: https://habr.com/ru/post/1697726/


All Articles