Suppose I have these two classes:
class Person (val name: String, val surname: String)
class Family (val nameFamily: String, val members: Set[Person])
Now in the main method instantiate two classes as follows:
val F1 = new Family ("Red", Set(P1, P2))
val P1 = new Person ("John", "Smith")
val P2 = new Person ("Luis", "Smith")
The main method allows me to enter the family members before their instantiation. I want this for my model. But if I enter the members before their creation, when I go to write:
println(F1.members)
I returns a Set (null).
If you write in the main people first, like this:
val P1 = new Person ("John", "Smith")
val P2 = new Person ("Luis", "Smith")
val F1 = new Family ("Red", Set(P1, P2))
I have no problem.
But I want to write instances in any order and in the end run a validation of family.
I can solve this problem. I mean, I can initialize my fields with instances created later.
Excuse me for the bad English translation.
UPLOAD #1
I have implemented a domain in Scala, I create instances of the domain with a DSL. My DSL allows me to instantiate classes in mixed order. For example, I create a Component, then add to this Component some Type. Then I create the Type I have added to Component. In the main method I can do it. As the last statement of the main I put validation. When starting validation, Type in the Component does not find anything, because these are instantiated later. This problem can be resolved only in the main with lazy? Or is there a solution at the domain level.