0
На рассмотрении

Book example about Association relationship

Bruno De angeli 3 года назад обновлен Alexander 3 года назад 1

Hi,

In page 22 I see the example of pseudo-code

class Professor is
   field Student student 
   //...
   method teach(Course c) is
      // ...
      this.student.remember(c.getKnowledge())

This example is used with Association relationship and I quote

Howev- er, since the student field is always accessible to any method of the Professor , the Student class is not just a dependency, but also an association

My question is regarding the pseudo code.

if in the pseudocode appear as "field Student student" that doesn´t mean that we are instantiating an instance of the Student object? if that is correct, and we are creating an instance of Student in Proffesor, that will not be a composition relationship ( because when the professorobject dies, the student object also die ) ?

thank you, Bruno.

+1
На рассмотрении

Hi Bruno!

Yes, you understand the implications of composition correctly. However, the Professor class wasn't meant to instantiate Student objects. It may receive a reference to a student by other means (via the constructor or some setter).

Сервис поддержки клиентов работает на платформе UserEcho