Android Question Composition and Aggregation

Eric H

Active Member
Licensed User
Longtime User
I have been using some newly acquired (read: n00b) OOP understanding to plan out object relationships for a project I am working on. Some of these objects will need to share a life-cycle (composition) and others will not share a life-cycle (aggregation).

Are these types of relationships available in B4a? If not, what would be the recommended work-around to simulate these type of object relationships?

For example:
University IS COMPOSED OF Departments
University
HAS AN AGGREGATE OF Professors

-Destroying the University object would destroy all of the Departments objects.
-Destroying the University object would not destroy the Professors objects.

Thanks!
Eric H
 

Eric H

Active Member
Licensed User
Longtime User
Are you saying that I would not create a separate class module for departments, that I would have to write all of the departments class info within the University class module for it to be destroyed together, and that I wouldn't be able to reference the department object from my main activity module? Or do I create separate class modules for University and Departments and then can only reference it from within the University class, or... ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should create a class for each of these "entities".

The question is what you should do with the instances. Don't confuse the classes with the instances.

It is really simpler to write the code than to understand the different terms.

B4X:
'University
Sub Class_Globals
 Dim Dep1, Dep2 As Department

End Sub

When the University instance will be destroyed then Dep1 and Dep2 instances will also be destroyed (assuming that there are no other references to the objects).
 
Upvote 0
Top