S
S
Svyatoslav Khusamov2017-01-05 12:54:53
Angular
Svyatoslav Khusamov, 2017-01-05 12:54:53

How to break recursive dependency of one class from another?

I have a User class.
It inherits the UserFriend class.
Next, I make the GetFriends method in the User class.
As a result, I get that the User class depends on the UserFriend class (because in the GetFriends method I create an array of UserFriend class instances).
And the UserFriend class depends on the User class, because there is inheritance.
How can I break this recursive dependency?
All this happens in Angular, where these dependencies are hardcoded (there is no use statement). That is why this problem arose.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Stepanov, 2017-01-12
@koronabora

RemoveUserFriend by giving each class a unique id of the appropriate dimension. All friends of the user - a list of these id.
When there are many identical objects, it is easier to enter an id for each object and use them to work with these objects using wrappers over the database, which will give the class or the desired class field by id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question