0
class Foo {}
class Bar {
  Foo foo;
}

Since Foo is a type of field of Bar, can we safely claim that Bar depends on Bar? What if foo == None? Does that mean Bar no longer depends on Bar?

1 Answer 1

1

This comes down to the difference between composition and aggregation. In the example you have

class Foo {}
class Bar {
  Foo foo;
}

Here, Bar can exist independent of Foo because foo can be null - a weak dependence.

However, if you had the same relationship defined this way:

class Foo {}

class Bar {
  Foo foo;
  Bar(Foo foo){
     this.foo = foo;
  }
}

then, it is a composition relationship, where Bar can not exist without Foo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.