473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Classes required for an application

I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a link
table such that each user can rate many songs and each song can be rated by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I really
need the Song object to be composed of a list of ratings in something of a
circular relationship.

Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the list
of ratings.

Is there another way to build these classes, or is the only way to describe
the relationship between a rating, a user and a song and between a song or
user and it's ratings?

I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.

Richard

Jul 9 '07 #1
8 1247
Your Song and User classes are just fine. However, your Rating class is the
problem. A Rating doesn't have a song; a song has a rating, or it may have
many ratings. Again, a Rating doesn't have a User, and neither does a User
have a rating. A rating may have a reference to a number of users, but these
are not users; they might only be User IDs from the database, so that you
can fetch information for any user if your requirements dictate that. The
other part of the rating is not a song, but a score. Does that help?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microsof t.com...
>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of a
circular relationship.

Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song or
user and it's ratings?

I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.

Richard

Jul 9 '07 #2
PS

"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microsof t.com...
>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of a
circular relationship.
Relationships can be circular. A man has a father that has children, one of
which is the the man.
>
Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.
If a rating has a song then the ratings for that song will include that
rating. I don't see what is "risky"? Are you talking about a data integrity
issue?
>
Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song or
user and it's ratings?
I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.
I would start with this:

class Rating
{
Song song;
User user;
int Rate;
}

class Song
{
List<RatingRatings
}
class User
{
List<RatingRatings
}

PS
>
Richard

Jul 9 '07 #3
PS

"Kevin Spencer" <un**********@nothinks.comwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
Your Song and User classes are just fine. However, your Rating class is
the problem. A Rating doesn't have a song;
If a rating doesn't have a song then what was being rated?

a song has a rating, or it may have
many ratings. Again, a Rating doesn't have a User,
so who did the rating?
and neither does a User have a rating.
Finally, I agree on this one
A rating may have a reference to a number of users, but these are not
users
I have no comment on this!!!!
they might only be User IDs from the database, so that you can fetch
information for any user if your requirements dictate that. The other part
of the rating is not a song, but a score. Does that help?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microsof t.com...
>>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of
a
circular relationship.

Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song
or
user and it's ratings?

I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.

Richard


Jul 9 '07 #4
Thanks, Your statement that a song has ratings makes sense, though I am not
sure if I just include user ids how I would display (e.g.) the user name
with each rating. Why not have the relationship that Song has many Ratings,
and rating has a User as then if I needed to include anoth user attribute in
my presentation, (e.g.)the user postcode, I would not need to make a change
to my rating class, just use the existing postcode from the user class?

From this model however I can get Songs, their Ratings and the corresponding
User (note there can only be one user per rating as aswell as score there is
revew text).

But there is no way to get Users and their corresponding Songs. In my mind I
can only navigate down the class structure Song.Rating[x].User not start
from User and navigate back to the corresponding Songs without complex
looping through all of the Songs. I may be missing something fundamental
here, but I would have thought that this was a pretty common problem.

Thanks, Richard

"Kevin Spencer" <un**********@nothinks.comwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
Your Song and User classes are just fine. However, your Rating class is
the problem. A Rating doesn't have a song; a song has a rating, or it may
have many ratings. Again, a Rating doesn't have a User, and neither does a
User have a rating. A rating may have a reference to a number of users,
but these are not users; they might only be User IDs from the database, so
that you can fetch information for any user if your requirements dictate
that. The other part of the rating is not a song, but a score. Does that
help?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microsof t.com...
>>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of
a
circular relationship.

Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song
or
user and it's ratings?

I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.

Richard


Jul 10 '07 #5
If a rating has a song then the ratings for that song will include that
rating. I don't see what is "risky"? Are you talking about a data
integrity issue?
Yes the risk is that when creating the objects both the List<ratingand the
rating.song need to be populated at the same time to ensure the data
integrity. It would seem that this is extra work that shouldn't be required.
Iif you just model the heirarchical relationship one way, then on the face
of it, you can derive that the father is the son's father and the son is the
father's son. However in practice I only know of how to navigate from the
parent to the child (father.son), not for child to parent.

Richard

"PS" <ec***********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP04.phx.gbl...
>
"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microsof t.com...
>>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of
a
circular relationship.

Relationships can be circular. A man has a father that has children, one
of which is the the man.
>>
Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

If a rating has a song then the ratings for that song will include that
rating. I don't see what is "risky"? Are you talking about a data
integrity issue?
>>
Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song
or
user and it's ratings?
>I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.

I would start with this:

class Rating
{
Song song;
User user;
int Rate;
}

class Song
{
List<RatingRatings
}
class User
{
List<RatingRatings
}

PS
>>
Richard


Jul 10 '07 #6
>However in practice I only know of how to navigate from the parent to the
>child (father.son), not for child to parent.
But a father could be a son and a son a father - otherwise evolution
wouldn't have got very far! You have people, then you have relationships,
similar to my other post, keep them separate and when required, using a
containing class to allow navigation.

Person
{
string name;
}

Relationship
{
RelationshipEnumType;
Person1;
Person2;
}

PersonRelationships
{
Person;
Relationship[];
}


"RichB" <rb****@koanga.comwrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
>If a rating has a song then the ratings for that song will include that
rating. I don't see what is "risky"? Are you talking about a data
integrity issue?

Yes the risk is that when creating the objects both the List<ratingand
the rating.song need to be populated at the same time to ensure the data
integrity. It would seem that this is extra work that shouldn't be
required. Iif you just model the heirarchical relationship one way, then
on the face of it, you can derive that the father is the son's father and
the son is the father's son. However in practice I only know of how to
navigate from the parent to the child (father.son), not for child to
parent.

Richard

"PS" <ec***********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP04.phx.gbl...
>>
"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microso ft.com...
>>>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of
a
circular relationship.

Relationships can be circular. A man has a father that has children, one
of which is the the man.
>>>
Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

If a rating has a song then the ratings for that song will include that
rating. I don't see what is "risky"? Are you talking about a data
integrity issue?
>>>
Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song
or
user and it's ratings?
>>I would be grateful for any assistance. I am very confused about this,
so
apologies if my question is confusing.

I would start with this:

class Rating
{
Song song;
User user;
int Rate;
}

class Song
{
List<RatingRatings
}
class User
{
List<RatingRatings
}

PS
>>>
Richard



Jul 10 '07 #7
PS

"RichB" <rb****@koanga.comwrote in message
news:OW*************@TK2MSFTNGP06.phx.gbl...
Thanks, Your statement that a song has ratings makes sense, though I am
not sure if I just include user ids how I would display (e.g.) the user
name with each rating.
You would look up the user via the key from the list of Users.
Why not have the relationship that Song has many Ratings,
and rating has a User as then if I needed to include anoth user attribute
in my presentation, (e.g.)the user postcode, I would not need to make a
change to my rating class, just use the existing postcode from the user
class?

From this model however I can get Songs, their Ratings and the
corresponding User (note there can only be one user per rating as aswell
as score there is revew text).

But there is no way to get Users and their corresponding Songs. In my mind
I can only navigate down the class structure Song.Rating[x].
There is no direct relationship between a user and a song unless they have
rated it.

User not start
from User and navigate back to the corresponding Songs without complex
looping through all of the Songs. I may be missing something fundamental
here, but I would have thought that this was a pretty common problem.

Thanks, Richard
Some relationships are not necessarily navigatable backwards. The son may
have a parent property but the parent only has a children property, not a
son property.

PS
>
"Kevin Spencer" <un**********@nothinks.comwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
>Your Song and User classes are just fine. However, your Rating class is
the problem. A Rating doesn't have a song; a song has a rating, or it may
have many ratings. Again, a Rating doesn't have a User, and neither does
a User have a rating. A rating may have a reference to a number of users,
but these are not users; they might only be User IDs from the database,
so that you can fetch information for any user if your requirements
dictate that. The other part of the rating is not a song, but a score.
Does that help?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microso ft.com...
>>>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of
a
circular relationship.

Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song
or
user and it's ratings?

I would be grateful for any assistance. I am very confused about this,
so
apologies if my question is confusing.

Richard



Jul 10 '07 #8
Thanks for all of your comments, this has given a lot of food for thought. I
think that I need to go back to my requirements and create a model around
the processes required, but I do think that actually rating, user and song
have a fairly loose association and the approaches suggested have
highlighted that to me.

Many Thanks.
Richard
"richB" <ri***@community.nospamwrote in message
news:4E**********************************@microsof t.com...
>I am trying to build a rating engine for a number of users for a list of
songs. I havea database design with a user table and a song table and a
link
table such that each user can rate many songs and each song can be rated
by
many users.

However I am a little stuck on the class design. I hope that this is the
correct place to post such a question and that someone can help with an
answer.

Simply put each rating has a user and a song, which leads me to three
classes

class Rating
{
Song song;
User user;
}

class Song{}
class User{}
This is the point at which I am slightly confused if I have a rating
object
then I can refer to the song by rating.song and the same for the user.
However If I just want to list all of the ratings for a song, then I
really
need the Song object to be composed of a list of ratings in something of a
circular relationship.

Whilst this seems to be supported in c#, it does seem to be risky if a
rating has a song, but the song does not include that rating within the
list
of ratings.

Is there another way to build these classes, or is the only way to
describe
the relationship between a rating, a user and a song and between a song or
user and it's ratings?

I would be grateful for any assistance. I am very confused about this, so
apologies if my question is confusing.

Richard

Jul 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
3
by: Chris | last post by:
Hi, I'm trying to append text from another class to a generic richTextBox that I've added to a Windows form. I can't seem to figure out how to expose the richTextBox to append text to it. ...
3
by: Jeremy S | last post by:
I wrote an ASP.NET application and pretty much separated out various layers of functionality into individual class files (e.g., dal.cs for all db access). It's currently all in one VS.NET project...
3
by: Joseph Geretz | last post by:
System.InvalidOperationException: WebServiceBindingAttribute is required on proxy classes. My environment: Visual Studio 2005, targeting FX 2.0; I've developed a Web Service which uses DIME to...
3
by: Juha Nieminen | last post by:
It occurred to me while developing an application: What happens if two (completely independent) base classes have the exact same virtual function, and then a derived class is derived from both,...
3
by: Glenn | last post by:
My current classic-ASP site has users, projects, roles and the 2.0 membership looks like a perfect fit, but I'm having trouble finding examples of how to have users that belong to different...
5
by: Sagar | last post by:
I am working on a migration project for a huge asp.net application now running in framwework 1.1 to dotnet 2.0 As a first step, I opened the .sln files of the project in VS.Net 2005. The...
12
by: Nathan Sokalski | last post by:
I have several CustomControls that I have written for my project. However, when I try to compile I recieve the following warning & errors: Warning 32 Could not resolve this reference. Could not...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.