Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to avoid cyclic dependencies? #7

Closed
danf0rth opened this issue Apr 29, 2018 · 1 comment
Closed

How to avoid cyclic dependencies? #7

danf0rth opened this issue Apr 29, 2018 · 1 comment

Comments

@danf0rth
Copy link

danf0rth commented Apr 29, 2018

Hi!

Lets say, we have a:

package state

import "city"

type State struct {
    ID uint64
    Name string
    Cities []city.City // The list of all cities in this state
}

...

package city

import "state"

type City struct {
    ID uint64
    Name string
    State *state.State // The state to which the city belongs
}

There is a problem of cyclic import, how to handle this kind of situations?
You can say, that we can put state and city into the same package, but...
if we add more realistic cases and examples, this is not a solution anymore:

type Department struct {
    City *city.City // Where is department located
}

and modify type City struct to following:

type City struct {
     // previous fields
    Departments []department.Department
}

Thank you!

@bxcodec bxcodec mentioned this issue Apr 30, 2018
Merged
@bxcodec
Copy link
Owner

bxcodec commented Apr 30, 2018

Hello there,

Sorry for late response,
So after figuring this problem a few months ago, I make many changes to all my entire project. But I forgot to update this one.

You can see the proposed changes in #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants