2 Replies - 1194 Views - Last Post: 23 March 2019 - 08:09 PM

#1 NantucketSleighride   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 119
  • Joined: 13-February 11

[Beginner] ways to link 'data' from different objects/classes

Posted 23 March 2019 - 09:32 AM

I wasn't really sure how to title this... But I've dabbled in coding and posted here before a few times. I'm not very good at programming, but I understand a lot of the basics of programming.

So - I'm fiddling a bit with Swift and with Python right now - and I sort of have two ideas of something I want to work on, and I wanted to ask a question about practices surrounding linking 'data' between object. I wish I could word that better - but I can't, so I'm going to have to give examples instead.

Now there are projects that are personal and just for fun, to get a little more into programming. I'm not looking to release anything or make some remotely professional.

One of my ideas is a little Board Game tracker - I'll have board games and users. The board games will have information like the name, min player count, max player count, release year, etc. The users class will just hold the user's name and then all their ratings for each game that they've rating.

I'm doing this in Python right now - which isn't exactly relevant since I'm not asking for code, but how to structure things, but I wanted to share.

I know how to make the classes and all that - my question comes from how to structure everything in a way that's clean and efficient when it comes to linking the ratings together.

I'll want to print out a game with an average rating based on the user ratings when I'm showing a game list. Or I'll want to show a print out of just that user's score for each game.

Do I create some class that goes inside the user class that is linked somehow to a specific board game, and holds an integer rating? Do I put something in the board game class that links to user object and then holds a rating? Do I have an entirely different class on its own that just holds ratings all on its own?

There are so many ways to do it - and I'm curious how people tend to approach this sort of thing. Because when I'm looking for ratings, either way I'm going to have to search through all these objects to collect them or see if they're even there.

Another thing I wanted to try in Swift was a sport-stat-tracker. I've got players and their basketball stats... When I'm creating a basketball game and tracking the stats - where do I store them when they're done? Does each player keep their own game stats? Is there a whole separate object just holding game stats and when I go to look up a player it has to go through every single game to get the stats?

I've never really worked on anything like this before - where I had a bunch of data that has to be linked and gone through to display in different ways, based on what you want to see: For instance, the board game will have an overall average of user scores, and each individual user score and I'll show it based on what you're looking up.

This is probably poorly worded and far too long. Hopefully someone will get the idea of what I'm trying to understand here.

Edit: Whoever moved this - thank you. I'd intended to put it in this forum and must have clicked the student forum by accident without realizing it. Sorry!

This post has been edited by NantucketSleighride: 23 March 2019 - 10:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: [Beginner] ways to link 'data' from different objects/classes

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6985
  • View blog
  • Posts: 23,751
  • Joined: 05-May 12

Re: [Beginner] ways to link 'data' from different objects/classes

Posted 23 March 2019 - 05:15 PM

This sort of depends... Are you looking at this from the strictly object oriented point of view? Or are you going a bit deeper and trying to look at how things end up being persisted? If you are looking at the persistence level, are you locked into using a RDBMS (relational database management system) or are you free to use a OODBMS (object oriented database management system)?
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11604
  • View blog
  • Posts: 19,726
  • Joined: 19-March 11

Re: [Beginner] ways to link 'data' from different objects/classes

Posted 23 March 2019 - 08:09 PM

Probably the easiest backend to use for something like this will be mysqlite. This will involve the least rigamarole and python will be able to talk to it reasonably handily.

The key though will be to ensure that you've isolated the code that deals with the persistent storage so that the rest of the code doesn't have to care about what sort of back end you're using. An ORM like SQLAlchemy is something you should look into. If this were a web project I'd suggest using django, since the django orm is quite good, but for a desktop app that probably comes with a lot of stuff you don't really want and would be more of a nuisance than a help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1