Hi Folks,
Most of my background has been working with databases so I tend to think about problems in terms of data. I know that objects can contain data but thinking of them as simply data holders can be a bad thing. I've been trying to correct myself in the way that I think of objects. I've coded Java for a couple of years now but I still I may be thinking subconsciously of groups of objects that hold data. Anyway, that's just a little background to see where I am coming from.
What I am looking for is a little guidance with a very simple problem. I have two classes in a system - Player and Competition. The Player class holds basic person information such as login, password (security is not an issue), name, etc. The Competition class holds information such as name, year, administrator, etc. A Player can register to particpate in many Competitions but they will usually just be in one. The application is a web app that uses a fair bit of JSP.
The scenario that I am thinking of is this. When the Player logs into the system and they want to view their Competition details, they need to select the Competition from a dropdown box. This means that the application has to know what Competition names to populate the drop down with. Since the application already has awareness of who the Player is it sounds to me as though the Player instance should be responsible for maintaining the Competition information. Does that sound right or are there things I am not thinking about?
I'm wondering which of the three methods is best:
[1] Each instance of the Player class contains a collection (e.g. a Vector) of registered Competitions.
[2] Each instance of the Competition has a reference to the associated Player instance.
[3] Have a method in the Player class that reads the database and retrieves all the Competitions on the fly and returns them in a Vector.
My thoughts...
[1] sounds like the best idea.
[2] I don't think I should be creating an object for every Competition since the competition information will be the same for every player. I am thinking that Competition data should exist in an application scope Vector that could be updated on the fly if any new Competitions were added (a rarity in itself, usually just once a year).
[3] this sounds like the process necessary for idea [1] except it would be performed every time the Player accesses a certain page. Sounds much better to read the information once, store it in the Player instance and be done with further database transactions.
I think I have it clear in my head but I just don't know if it is clear AND correct.
I hope I provided enough information. It is purposefully vague and I am only talking about a small piece of the application. I can provide any other information should I not have done a good job of asking my question.
Cheers, Max
Most of my background has been working with databases so I tend to think about problems in terms of data. I know that objects can contain data but thinking of them as simply data holders can be a bad thing. I've been trying to correct myself in the way that I think of objects. I've coded Java for a couple of years now but I still I may be thinking subconsciously of groups of objects that hold data. Anyway, that's just a little background to see where I am coming from.
What I am looking for is a little guidance with a very simple problem. I have two classes in a system - Player and Competition. The Player class holds basic person information such as login, password (security is not an issue), name, etc. The Competition class holds information such as name, year, administrator, etc. A Player can register to particpate in many Competitions but they will usually just be in one. The application is a web app that uses a fair bit of JSP.
The scenario that I am thinking of is this. When the Player logs into the system and they want to view their Competition details, they need to select the Competition from a dropdown box. This means that the application has to know what Competition names to populate the drop down with. Since the application already has awareness of who the Player is it sounds to me as though the Player instance should be responsible for maintaining the Competition information. Does that sound right or are there things I am not thinking about?
I'm wondering which of the three methods is best:
[1] Each instance of the Player class contains a collection (e.g. a Vector) of registered Competitions.
[2] Each instance of the Competition has a reference to the associated Player instance.
[3] Have a method in the Player class that reads the database and retrieves all the Competitions on the fly and returns them in a Vector.
My thoughts...
[1] sounds like the best idea.
[2] I don't think I should be creating an object for every Competition since the competition information will be the same for every player. I am thinking that Competition data should exist in an application scope Vector that could be updated on the fly if any new Competitions were added (a rarity in itself, usually just once a year).
[3] this sounds like the process necessary for idea [1] except it would be performed every time the Player accesses a certain page. Sounds much better to read the information once, store it in the Player instance and be done with further database transactions.
I think I have it clear in my head but I just don't know if it is clear AND correct.
I hope I provided enough information. It is purposefully vague and I am only talking about a small piece of the application. I can provide any other information should I not have done a good job of asking my question.
Cheers, Max