|
I am just trying to learn OOAD using c# at present, by designing a simple song management system.
Within this system there are songs which have one to many artists. I therefore designed classes as follows:
<br />
class Song<br />
{<br />
Artist[] artists; <br />
}<br />
<br />
class Artist<br />
{<br />
String name;<br />
}<br />
<br />
class SongList<br />
{<br />
List<Song> songs;<br />
}<br />
<br />
This seems to work OK I could in my output list each 'Song in songs' and show the artist by looping through each one in that song.
Where I have got really confused is another requirement which I might have to list all Artists along with their songs. How can I build a collection of artists and list the songs for each artist if artist is an attribute of a song. I can after all do song.artist, but I cannot access song from the artist: artist.song.
On thinking further I decided that an artist is not actually an attribute of song, but just a loose relationship. If they are just to seperate objects in a collection how do I implement this loose relationship between the two objects.
Any help, including references to books or other material which may be of help would be greatly appreciated. I son't think that I am thinking correctly to understand this, so any help that will assist me in thinking the right way would be greatly appreciated.
Thanks,
Richard
|
|
|
|
|
rb157 wrote: How can I build a collection of artists and list the songs for each artist if artist is an attribute of a song. I can after all do song.artist, but I cannot access song from the artist: artist.song.
You could have a dictionary with the artist as the key and a list of songs as the value, e.g.
Dictionary<Artist, List<Song>> songsByArtist = new Dictionary<Artist, List<Song>>(); You'd then have to loop through all the songs, loop through the artists, check if they already exists in the dictionary (if not add the key-value pair) and then add the song to the List in the value part.
As for the further thinking I'm also having a think about it (too early in the morning (oops, afternoon ))
|
|
|
|
|
rb157 wrote: How can I build a collection of artists and list the songs for each artist if artist is an attribute of a song. I can after all do song.artist, but I cannot access song from the artist: artist.song.
Sure you can
<Artist><Song><Song>class Song
{
List<Artist> artists;
}
class Artist
{
String name;
List<Song> songs;
}
class SongList
{
List<Song> songs;
}
</Song></Song></Artist>
|
|
|
|
|
Thanks, I did wonder about these sort of circular relationships and whether they are wise... i.e. if for some reason the Song and Artist objects do not replicate each other correctly then a different result is obtained when outputing song.artist[i] than artist.song[i]. However if circular relationships are generally considered appropriate, then I am quite happy with that approach.
My concern is that in the real world the artist is probably not an attribute of the song and the Song not of the artist, in that one is not part of the other, just has an other type of relationship: In the same way that the Driver is not an attribute of a car. However if a driver is modelled in the same way as a steering wheel in its relationship then that is fine. I would appreciate comment on this point.
The approach provided by Ed... This would work artist to Song, but I think that another list would be required to output song by artist:
Dictionary <Song, List <Artist>>
Which is fine but would appear to be an amount of processing which is far in excess of mike's suggestion.
Thanks,
Richard
|
|
|
|
|
rb157 wrote: I did wonder about these sort of circular relationships and whether they are wise
I apologize. I was in no way suggesting it was wise, only that it could be done. In order to know if it is wise much more information is required. I would also guess that a design utilizing one or more interfaces would most likely be superior.
|
|
|
|
|
Thanks, can you give me an idea of the sort of things that I would need to consider in establishing if this was an apropriate approach, you also mention interfaces, in what respect might these be utilised? I understand what interfaces do, but can't quite work out how they assist in sorting out the relationships.
Thanks, Richard
|
|
|
|
|
I think it a classic design question.
Do you keep data "heavy" to optimize queries or do you keep the data light and don't really care about performance for queries ?
One other question to ask yourself is :
What is the most important basic information ? is it the artist ? the song ? the CD (for example) ?
Will you enter an artist and then all the song that he wrote ?
Will you enter a CD with the artist(s) and all the songs?
You have to remember that the data, in this particular case is really static; keeping cross reference should be easy.
|
|
|
|
|
Thanks, my feeling at present is actually that I need to design for the mosst likely scenario, then provide a dictionary for the alternative. I expect that the default view will be of songs with the artists as a part of them. I feel really quite unsure about the cross referencing as it would seem to create far too much dependency between the two objects. It may work perfectly well, but I could find that I add a further attribute to song which is similar in the future, for example what if I add a rating to the song, made by a user I then have a link through user to rating and through rating through to song. The cross referencing may then become quite complex if I want to do some association regarding user rating of artists.
I would rather then follow a common approach and provide a one way reference, with the return referencing created when a requirement develops to provide a dictionary type linking between user and artist.
Does this make sense or would you think that the cross referencing up and down the 'tree' is still an appropriate way, or is my second scenario completely different and therefore it be appropriate to employ two approaches.
I no that there are a lot of assumptions required here, but I would appreciate views on whether my thinking is sound.
Many Thanks,
Richard
|
|
|
|
|
is a songlist really a class or a collection of objects?
David
|
|
|
|
|
Why don't you look at providing a Many:Many relationship between the songs and artists. Ok, sure this is best performed back in the data, but you can then easily place a "LINK" class between the Songs and Artists. That way you don't have a true circular reference but you will reap the benefits.
Songs (1) ---> (M) SongArtistLink (M) <--- (1) Artists
I'm using this approach in our own in-house solution on a number of various entities. In the songs class, add a Readonly Artists property which references the "LINK" class. In the artists class, add a Readonly Songs property which references the "LINK" class.
We've seen no perceived or measurable performance penalties using this approach and because the link is done in "data" you can then query the data at any time using any of the available tools.
Hope this helps.
Edward Steward
edwardsteward@optusnet.com.au
|
|
|
|
|
Thanks, I had been considering this, and I think that it provides the most flexible solution and models the relationship correctly, artist is no more part of the song than say driver is of a car, they just have a loose relationship which is best modelled as that.
Thanks again,
Richard
|
|
|
|
|
Cool. The best thing I like about a M:M relationship (link table) is that is easy to replicate that model out to other entities. i.e. Songs & Albums, Artists and genres, etc.
One of the things that I quite enjoy is the fact that I can use a single link table for multiple relationships. This is because we use a GUID as a primary key due to our replication needs.
Edward Steward
edwardsteward@optusnet.com.au
|
|
|
|
|
I have an object model in line with GOF Composite pattern. The database has 2 tables presently. One to store the component(composite or primitive) and the other to store association/relationship. Looking some direction/advice on how to go about loading the composite from database. Thanks.
|
|
|
|
|
See if this[^] helps you get started
|
|
|
|
|
|
I'm in need of a little push in the right direction and I'm hoping some experts on this forum can help in getting me going in that direction.
I would like to develop a cross-platform application which would run as a client-program only but has the potential of running as a client-server program.
The application is basically a game application that needs a database-layer, an application layer, and a GUI layer.
The requirements are the following: Cross platform a must. Intuitive GUI. Easy access to Database so user can make whatever changes are necessary. Separate layers so that work can be done on one layer and not effect another.
When it came to the GUI layer I would like to use WxPython for the GUI. In researching this product it does exactly the things the application design requires however does WxPython interface with C++? C#? How does it interface? Sockets? Events? The answers here will determine how the logic layer will be built.
Also not sure which Database to use. I'm comfortable with SQL databases but again, the database must be cross-platform compatible (if that makes a difference anyways with the database). Perhaps XML would work better. Last attempt with XML proved to be slow but was using Java as the logic layer. Could have something to do with it, maybe not.
I will continue to browse through the articles here to see if anything can be of help, but for those who are far more experienced in this stuff, if you have general information that could help I would be much appreciative.
Thanks for any help!
|
|
|
|
|
brdavid wrote: The application is basically a game application
brdavid wrote: Cross platform a must.
What platforms? Nintendo? WII? PlayStation.....?
That's a tall order and I am not sure apps for Games use a Database so where does that requirement come from?
brdavid wrote: I will continue to browse through the articles here to see if anything can be of help, but for those who are far more experienced in this stuff, if you have general information that could help I would be much appreciative.
I suggest you seek out more Gaming specific information sources.
|
|
|
|
|
led mike wrote: What platforms? Nintendo? WII? PlayStation.....?
Windows XP/2000 possibly Vista
Mac OSX
Linux (popular distros such as Ubunto)
Perhaps the use of the word "game" is misleading. This is a Windows "type" application that revolves around a "roleplaying" game. The application does nothing more than automate tasks, print sheets, calculate numbers, run random generators, update the database, run queries from the database and so on. So this is pretty much a standard application, and less of a "game".
|
|
|
|
|
brdavid wrote: The application is basically a game application that needs a database-layer, an application layer, and a GUI layer.
Cross-platform for what ? the database layer, the application layer or the GUI layer ?
anyway, doing cross-platform development is a challenge, you need to do the following, have at least an expert for each type of platform you want to develop on; these people will help you write platform specific code and help you create an abstraction layer between your "engine" and the different platforms.
For example, file access, graphics, DB, ...
For the GUI part, you can use a toolkit that is supported by all platforms, the upside is that it can be faster to develop, but your application will look ugly on all platforms, those kind of toolkit usually do not support native look-and-feel.
|
|
|
|
|
True, but I guess my main area of interest right now is if anyone knows of any leads where WxPython and C++ and a database are used either in a multi-tier application or perhaps single tier.
Thanks!
|
|
|
|
|
How about FireBird[^] for the database layer, that's cross-platform and allows you to use SQL. It has interfaces for Mono & MS.NET as well as C, C++ etc. The upper language choices are really a matter of preference.
|
|
|
|
|
hi everybody,
Iam new to design pattern concept , I want to know in which scenario we are using singleton pattern in our appl.
I need exact scenario because i had some examples and gone the theory in books
i want applicable knowledge in application development.
Thanks in advance for replay,
|
|
|
|
|
Hi shakeela,
one of the case you can use singleton pattern is to create a connection for your data base application.
satyaki mishra
|
|
|
|
|
satyaki mishra wrote: one of the case you can use singleton pattern is to create a connection for your data base application.
I don't believe that statement is particualrly helpful
|
|
|
|
|
And it's quite controversial use.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|