How to define a direct association?

119 Views Asked by At

According to the code below, could you please tell me how (and if it possible to) refer to the array defined inside the class ComputationUnit from the class Service?

class ComputationUnit {
    contains Method[1..*] methods 
}

class Method {
    String name
    String signature
    Object sourceCode
    contains Parameter[1..*] parameters
}

class Servic e {
    contains Comment comment
    contains Parameter[1..*] parameters
    contains Contract[0..*] contracts
    refers Method[] methods //How can I refer to the array defined inside the ComputationUnit class?
}
1

There are 1 best solutions below

0
On

You can't. It doesn't make sense. There isn't just one array defined inside the ComputationUnit class, there's an array defined inside each instance of ComputationUnit. Which instance do you want?

Instead, you should write:

refers ComputationUnit unit

and then access the array as needed from the reference to the unit.