I've been spending some time on 're-tuning' some of my OOP understanding, and I've come up against a concept that is confusing me.
Lets say I have two objects. A
user object and an
account object. Back to basics here, but each object has state, behaviour and identity (often referred to as an entity object).
user object manages behaviour purely associated with a user, for example we could have a
login(credentials) method that returns if successfully logged in or throws exception if not.
account object manages behaviour purely associated with a users account. For example we could have a method checkActive() that checks if the account is active. The account object checks if the account has an up-to-date subscription, checks if there are any admin flags added which would make it inactive. It returns if checks pass, or throws exception if not.
Now here lies my problem. There is clearly a relationship between
account, but I feel that there are actually two TYPES of association to consider. One that is data driven (exists only in the data/state of the objects and the database) and one that is behaviour driven (represents an object call to methods of the associated object).
Data Driven Association
In the example I have presented, there is clearly a data association between
account. In a database schema we could have the following table:
----------------- USER_ACCOUNTS ----------------- id user_id ----------------
When we instantiate the
account and load the database data into it, there will be a class variable containing
user_id. In essence, the
account object holds an integer representation of
Behaviour Driven Association
Behaviour driven associations are really the dependencies of an object. If object A calls methods on object B there is an association going from A to B. A holds an object representation of B.
In my example case, neither the
user object nor the
account object depend on each other to perform their tasks i.e. neither object calls methods on the other object. There is therefore no behaviour driven association between the two and neither object holds an object reference to the other.
Is the case I presented purely a case of entity representation? The association between
account is always present, but its being represented in different ways?
user entity has an identity that can be represented in different forms. It can be represented as an object (the instantiated
user object) or as a unique integer from the users table in the databases.
Is this a formalised way of recognising different implementations of associations or have I completely lost my mind?
One thing that bugs me is how would I describe the differences in UML or similar? Or is it just an implementation detail?