News for hackers. Stuff that matters.
Re:When Objects Are Not Enough by bob1029 on Thursday July 25, 2024 @08:00PM (#41074704)
Think about a collection of one related type on another, such as Customer -> Accounts + Account -> Customers. In banking, it is possible for one customer to have many accounts, and for each account to have many customers.

OOP will let you express this kind of problem from a data modeling perspective (List<T> on each type), but from a serialization and dependency perspective you have to pick a "winner". In banking, it is unclear which type should be king.

The relational approach is to use a join table. Model the actual relationship itself and its relevant attributes (role on the account, beneficiary %, etc). This also handles any arbitrary graph of accounts and customers, assuming you are using a modern database engine that supports with recursive & cycle keywords.

ORMs will blow up on this kind of thing without special handling.

Re:When Objects Are Not Enough by facturi on Friday July 26, 2024 @05:14AM (#41077062)
This is related: Why relations are better than objects https://www.cell-lang.net/relations.html
Re:When Objects Are Not Enough by eadmund on Friday August 02, 2024 @11:30AM (#41139677)
> OOP will let you express this kind of problem from a data modeling perspective (List<T> on each type), but from a serialization and dependency perspective you have to pick a "winner". In banking, it is unclear which type should be king.

Serialisation is not necessarily a big deal, just pick one and refer back to it — check out PRINT-CIRCLE, Sharpsign Equal-Sign and Sharpsign Sharpsign in Common Lisp.

For dependencies, I think this only matters with strong type systems which don’t support forward declarations, or which lack null references/empty containers (if the language does support that, just create one object without any references, create the second, then add the second to the first).