DEV Community

loading...

Discussion on: How you can reduce usage of getter methods in your code

Collapse
aleksikauppila profile image
Aleksi Kauppila Author

Some collections contain data structures, some contain objects.

Footballing example:

  • Competitition contains matches
    • Exposes Standings by calculating them from Match results
    • Cannot contain matches from other competitions
    • Matches are entities
    • Matches collection is hidden, but used internally to create Standings.

  • Match contains events (goals, bookings, substitutions)
    • Exposes MatchStatistics by calculating them from Event occurrences by home and away team
    • Cannot contain events from other matches
    • Events are data structures
    • Events collection is hidden, but used internally to create MatchStatistics
Thread Thread
zhu48 profile image
Zuodian Hu

Sorry, I'm not sure if you're trying to make a point or not?

Thread Thread
aleksikauppila profile image
Aleksi Kauppila Author

Yes :D there may be sorting happening inside an aggregate entity and that membership in a collection needs to be checked whether we are dealing with objects or data structures. However the objects in a collection usually only serve one aggregate, eg. Match / Events. That's why ordering algorithm can be coded into a compareTo -method of that object inside the collection. No need to order based on exposed attributes.

Thread Thread
zhu48 profile image
Zuodian Hu

Oh, OK. Yeah I agree with you; for modularity and stability, it's better to opaquely define how comparison should work than to expose data and let the user misuse and depend on that data. I think the big disagreement most people have with that idea is that encapsulation isn't always the most important thing in the world.

Forem Open with the Forem app